2025-05-01 01:48:08 -07:00

46 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Dictionary source
The [Dictionary source](xref:UnityEngine.Localization.SmartFormat.Extensions.DictionarySource) extracts objects with a matching Key from an [IDictionary](https://docs.microsoft.com/en-us/dotnet/api/system.collections.idictionary) or [IDictionary<string, object>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-).
When evaluating an IDictionary, if the Key is not a string, the Dictionary source first converts it to a string using the objects ToString method. The case sensitivity of the comparison is determined by the Smart Form [Case Sensitivity](../LocalizationSettings.md#smart-format-settings) option.
<table>
<tr>
<th><strong>Example Smart String</strong></th>
<th><strong>Arguments</strong></th>
<th><strong>Result</strong></th>
</tr>
<tr>
<td>{SomeKey}</td>
<td>
[!code-cs[](../../DocCodeSamples.Tests/SmartStringSamples.cs#args-dict-1)]
</td>
<td>999</td>
<tr>
<td>Hello {Name} {Surname}</td>
<td>
[!code-cs[](../../DocCodeSamples.Tests/SmartStringSamples.cs#args-dict-2)]
</td>
<td>Hello Gordon Freeman</td>
<tr>
<td>{Name} {Surname} scored {1:Score} points</td>
<td>
[!code-cs[](../../DocCodeSamples.Tests/SmartStringSamples.cs#args-dict-3)]
</td>
<td>Gordon Freeman scored 153 points</td>
</table>
The following example shows how a dictionary could be provided as an argument.
[!code-cs[](../../DocCodeSamples.Tests/SmartStringSamples.cs#args-dict-example)]