docs.unity3d.com
    Show / Hide Table of Contents

    Class SmartFormatter

    This class contains the Format method that constructs the composite string by invoking each extension.

    Inheritance
    Object
    SmartFormatter
    Namespace: UnityEngine.Localization.SmartFormat
    Syntax
    [Serializable]
    public class SmartFormatter : ISerializationCallbackReceiver

    Constructors

    SmartFormatter()

    Creates a new instance of SmartFormatter.

    Declaration
    public SmartFormatter()

    Properties

    FormatterExtensions

    Gets the list of IFormatter formatter extensions.

    Declaration
    public List<IFormatter> FormatterExtensions { get; }
    Property Value
    Type Description
    List<IFormatter>

    Parser

    Gets or set the instance of the UnityEngine.Localization.SmartFormat.Core.Parsing.Parser

    Declaration
    public Parser Parser { get; set; }
    Property Value
    Type Description
    UnityEngine.Localization.SmartFormat.Core.Parsing.Parser

    Settings

    Get the SmartSettings for Smart.Format

    Declaration
    public SmartSettings Settings { get; set; }
    Property Value
    Type Description
    SmartSettings

    SourceExtensions

    Gets the list of ISource source extensions.

    Declaration
    public List<ISource> SourceExtensions { get; }
    Property Value
    Type Description
    List<ISource>

    Methods

    AddExtensions(IFormatter[])

    Adds each extensions to this formatter. Each extension must implement IFormatter.

    Declaration
    public void AddExtensions(params IFormatter[] formatterExtensions)
    Parameters
    Type Name Description
    IFormatter[] formatterExtensions

    AddExtensions(ISource[])

    Adds each extensions to this formatter. Each extension must implement ISource.

    Declaration
    public void AddExtensions(params ISource[] sourceExtensions)
    Parameters
    Type Name Description
    ISource[] sourceExtensions

    Format(IList<Object>, String)

    Replaces one or more format items in a specified string with the string representation of a specific object.

    Declaration
    public string Format(IList<object> args, string format)
    Parameters
    Type Name Description
    IList<Object> args

    The list of objects to format.

    String format

    A composite format string.

    Returns
    Type Description
    String

    Returns the formatted input with items replaced with their string representation.

    Format(IFormatProvider, IList<Object>, String)

    Replaces one or more format items in a specified string with the string representation of a specific object.

    Declaration
    public string Format(IFormatProvider provider, IList<object> args, string format)
    Parameters
    Type Name Description
    IFormatProvider provider

    The IFormatProvider to use.

    IList<Object> args

    The object to format.

    String format

    A composite format string.

    Returns
    Type Description
    String

    Returns the formatted input with items replaced with their string representation.

    Format(IFormatProvider, String, Object[])

    Replaces one or more format items in a specified string with the string representation of a specific object.

    Declaration
    public string Format(IFormatProvider provider, string format, params object[] args)
    Parameters
    Type Name Description
    IFormatProvider provider

    The IFormatProvider to use.

    String format

    A composite format string.

    Object[] args

    The object to format.

    Returns
    Type Description
    String

    Returns the formatted input with items replaced with their string representation.

    Format(String, Object[])

    Replaces one or more format items in a specified string with the string representation of a specific object.

    Declaration
    public string Format(string format, params object[] args)
    Parameters
    Type Name Description
    String format

    A composite format string.

    Object[] args

    The object to format.

    Returns
    Type Description
    String

    Returns the formatted input with items replaced with their string representation.

    Format(FormattingInfo)

    Format the UnityEngine.Localization.SmartFormat.Core.Formatting.FormattingInfo argument.

    Declaration
    public virtual void Format(FormattingInfo formattingInfo)
    Parameters
    Type Name Description
    UnityEngine.Localization.SmartFormat.Core.Formatting.FormattingInfo formattingInfo

    FormatInto(IOutput, String, Object[])

    Writes the formatting result into an UnityEngine.Localization.SmartFormat.Core.Output.IOutput instance.

    Declaration
    public void FormatInto(IOutput output, string format, params object[] args)
    Parameters
    Type Name Description
    UnityEngine.Localization.SmartFormat.Core.Output.IOutput output

    The UnityEngine.Localization.SmartFormat.Core.Output.IOutput where the result is written to.

    String format

    The format string.

    Object[] args

    The objects to format.

    FormatWithCache(ref FormatCache, String, IList<Object>)

    Replaces one or more format items in a specified string with the string representation of a specific object, using the UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache.

    Declaration
    public string FormatWithCache(ref FormatCache cache, string format, IList<object> args)
    Parameters
    Type Name Description
    UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache cache

    The UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache to use.

    String format

    A composite format string.

    IList<Object> args

    The objects to format.

    Returns
    Type Description
    String

    Returns the formatted input with items replaced with their string representation.

    FormatWithCache(ref FormatCache, String, IFormatProvider, IList<Object>)

    Replaces one or more format items in a specified string with the string representation of a specific object, using the UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache.

    Declaration
    public string FormatWithCache(ref FormatCache cache, string format, IFormatProvider formatProvider, IList<object> args)
    Parameters
    Type Name Description
    UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache cache
    String format
    IFormatProvider formatProvider
    IList<Object> args
    Returns
    Type Description
    String

    FormatWithCacheInto(ref FormatCache, IOutput, String, Object[])

    Writes the formatting result into an UnityEngine.Localization.SmartFormat.Core.Output.IOutput instance, using the UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache.

    Declaration
    public void FormatWithCacheInto(ref FormatCache cache, IOutput output, string format, params object[] args)
    Parameters
    Type Name Description
    UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache cache

    The UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache to use.

    UnityEngine.Localization.SmartFormat.Core.Output.IOutput output

    The UnityEngine.Localization.SmartFormat.Core.Output.IOutput where the result is written to.

    String format

    The format string.

    Object[] args

    The objects to format.

    GetFormatterExtension<T>()

    Searches for a Formatter Extension of the given type, and returns it. This can be used to easily find and configure extensions. Returns null if the type cannot be found.

    Declaration
    public T GetFormatterExtension<T>()
        where T : class, IFormatter
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetNotEmptyFormatterExtensionNames()

    Gets all names of registered formatter extensions which are not empty.

    Declaration
    public List<string> GetNotEmptyFormatterExtensionNames()
    Returns
    Type Description
    List<String>

    GetSourceExtension<T>()

    Searches for a Source Extension of the given type, and returns it. This can be used to easily find and configure extensions. Returns null if the type cannot be found.

    Declaration
    public T GetSourceExtension<T>()
        where T : class, ISource
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Events

    OnFormattingFailure

    Event raising, if an error occurs during formatting.

    Declaration
    public event EventHandler<FormattingErrorEventArgs> OnFormattingFailure
    Event Type
    Type Description
    EventHandler<FormattingErrorEventArgs>

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • SmartFormatter()
    • Properties
      • FormatterExtensions
      • Parser
      • Settings
      • SourceExtensions
    • Methods
      • AddExtensions(IFormatter[])
      • AddExtensions(ISource[])
      • Format(IList<Object>, String)
      • Format(IFormatProvider, IList<Object>, String)
      • Format(IFormatProvider, String, Object[])
      • Format(String, Object[])
      • Format(FormattingInfo)
      • FormatInto(IOutput, String, Object[])
      • FormatWithCache(ref FormatCache, String, IList<Object>)
      • FormatWithCache(ref FormatCache, String, IFormatProvider, IList<Object>)
      • FormatWithCacheInto(ref FormatCache, IOutput, String, Object[])
      • GetFormatterExtension<T>()
      • GetNotEmptyFormatterExtensionNames()
      • GetSourceExtension<T>()
    • Events
      • OnFormattingFailure
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023