.Net includes a wide range of built in formatters to control the output when converting an object to a string e.g. ToString("N2"). How can I test if a given format string is actually valid?
If I pass a garbage formatter ToString(...) then the output seems to be the literal of that formatter. For example (in my en locale):
10.ToString("F"); // Outputs '10.00'
10.ToString("typo"); // Outputs 'typo'
I am trying to catch the case where a format has been overridden in one of our translations (perhaps by a non-developer), and the format has been accidentally typo'd.
It seems strange that an invalid formatter is allowed through without exception, and even more strange that when this case does occur, the invalid formatter is used as the output instead of falling back to the source object.