Version: Unity 7.0 Alpha (7000.0)
Language : English
Default source
Key value pair source

Dictionary source

Extract a value from a dictionary by matching the placeholder selector against its keys.

The Dictionary source resolves a selector against an IDictionary, a generic IDictionary<string, object>, or a dynamic ExpandoObject. It returns the value whose key matches the selector. When the dictionary key is not a string, the source converts it with ToString before comparing.

The key comparison uses the case sensitivity setting of the formatter.

You can nest dictionaries and drill into them with dot notation, for example {Numbers.One}. Put the nullable operator before a key, as in {City?.Name}, to get an empty result, not an error, when City is null or has no Name key. A missing City key is still an error.

Smart String Arguments Result
{SomeKey} { ["SomeKey"] = 999 } 999
Hello {Name} {Surname} { ["Name"] = "Gordon", ["Surname"] = "Freeman" } Hello Gordon Freeman
{Numbers.One} {Letters.A} nested dictionaries 1 a
var args = new Dictionary<string, object>
{
    ["Name"] = "Gordon",
    ["Surname"] = "Freeman",
};

// "Hello Gordon Freeman"
Smart.Format("Hello {Name} {Surname}", args);

Additional resources

Default source
Key value pair source
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961