For many reasons, a .NET developer should use composite formatting. (Culture-specific, no P/Invoke cost, string interpolation, etc) However, sometimes it is desirable to have a C-style format string, as when sharing localization strings across platforms.
swprintf is generally sufficient, but:
- It does not handle
paramscorrectly. (Values remain boxed as
objectand the format becomes the pointer value)
swprintfis disallowed for Windows Store apps, we must call the
Thus, we use a regular expression to parse the format string, and then call the approriate native API according to the parameter type.
To improve sharing with iOS code, this includes
%@ as an acceptable format specificer. Its behavior will match the culture-invariant
ToString of the parameter.