Localizing formatting functions instead of properties in VS.NET resources
Posted
by LexL
on Stack Overflow
See other posts from Stack Overflow
or by LexL
Published on 2010-05-20T10:55:31Z
Indexed on
2010/05/20
11:00 UTC
Read the original article
Hit count: 162
visual-studio-2010
|c#
I noticed that .NET framework uses formatting functions, generated the same way localizable string are.
There is a resource file Resources.resx with resource string TestString. So you may use it in code like this:
string localizableValue = Resources.TestString;
Now, imagine you need a formattable localizable string, to use it in string.Format function. So everytime you use it, you have to write something like this:
string localizableFormattedValue = string.Format(Resources.TestFormatString, someParam1, someParam2);
The observation says that in .NET framework generated resource classes already include the above construction. So instead of string property, a string function is generated. The resulting code looks like this:
string localizableFormattedValue = Resources.TestFormatString(someParam1, someParam2);
The question is - how do they do this? Is it some custom Microsoft feature (resx generator) or I'm missing something obvious?
© Stack Overflow or respective owner