1. The IFormatProvider.GetFormat( ) takes a System.Type parameter and
when this function is called by string.Format( ) the value of the
parameter is System.ICustomFormatter. This makes no sense to me.
When would the type be anything other than ICustomFormatter? Does
anyone have a sample implementation of this function? The
System.Globalization.NumberFormatInfo class implements this interface
with the following code (based on my rudimentary IL decompile skills):
public object GetFormatInfo(System.Type formatType)
{
if(formatType == typeof(System.Globalization.NumberFormatInfo)
{
return this;
}
else
{
return null;
}
}
Unfortunately, this implementation does not work on my own classes
that implement ICustomFormatter because the value of formatType that
is passed in from string.Format is an ICustomFormatter and not the
type of my class that implements ICustomFormatter.
2. Also, when calling ToString(IFormatProvider provider) on an
enumeration the implementation completely ignores the IFormatProvider
parameter. Why is this? If I want to provide custom formatting for
my enumeration or perhaps localize the enumeration name I should be
able to specify a format provider and actually have it affect the
provider. The current implementation simply calls Enum.ToString()
(notice not parameters).
3. Lastly, the Enum.ToString(string format, IFormatProvider provider)
also seems to not take in to consideration the full formatting
functionality and only checks for a few formatting strings without any
consideration of the provider parameter.
Any suggested workarounds? Any sample code on how to implement
ICustomFormatter and IFormatProvider?
Thanks,
Mark