Skip to content

Commit 79a38c2

Browse files
ResourceStringExtension: adding additional function to accomodate optional value in x:Bind compiled function
1 parent 3c2123a commit 79a38c2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/ResourceStringExtension.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ protected override object ProvideValue()
3333
return GetValue(this.Name, this.Language);
3434
}
3535

36+
/// <summary>
37+
/// Gets a string value from resource file associated with a resource key.
38+
/// </summary>
39+
/// <param name="name">Resource key name.</param>
40+
/// <returns>a string value from resource file associated with a resource key.</returns>
41+
public static string GetValue(string name)
42+
{
43+
// This function is needed to accomodate compiled function usage without second paramater,
44+
// which doesn't work with optional values.
45+
return resourceLoader.GetString(name);
46+
}
47+
3648
/// <summary>
3749
/// Gets a string value from resource file associated with a resource key.
3850
/// </summary>
@@ -44,7 +56,7 @@ public static string GetValue(string name, string language = "")
4456
{
4557
if (string.IsNullOrEmpty(language))
4658
{
47-
return resourceLoader.GetString(name);
59+
return GetValue(name);
4860
}
4961

5062
// Not using ResourceContext.GetForCurrentView nor GetForViewIndependentUse
@@ -53,5 +65,6 @@ public static string GetValue(string name, string language = "")
5365

5466
return resourceMap.GetValue(name, resourceContext).ValueAsString;
5567
}
68+
5669
}
5770
}

0 commit comments

Comments
 (0)