I was trying to create an IFormatProvider implementation that would recognize custom format strings for DateTime objects. Here is my implementation:
<
The short explanation is that while
DateTime.ToString(string format, IFormatProvider provider)
lets you pass anything implementing IFormatProvider as one of its parameters, it actually only supports 2 possible types implementing IFormatProvider inside its code:
DateTimeFormatInfo or CultureInfo
If your parameter cannot be casted (using as) as either or those, the method will default to CurrentCulture.
String.Format is not limited by such bounds.