Dictionary source
Extract a value from a dictionary by matching the placeholder selector against its keys.
読み終わるまでの所要時間 1 分最終更新 23日前
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 . Put the nullable operator before a key, as in , to get an empty result, not an error, when is or has no key. A missing key is still an error.
{Numbers.One}{City?.Name}CitynullNameCitySmart String | Arguments | Result |
|---|---|---|
| | 999 |
| | Hello Gordon Freeman |
| nested dictionaries | 1 a |
var args = new Dictionary<string, object> { ["Name"] = "Gordon", ["Surname"] = "Freeman", }; // "Hello Gordon Freeman" Smart.Format("Hello {Name} {Surname}", args);