System.IFormatProvider.GetFormat Method

Returns an object that provides formatting services for the specified type.


public object GetFormat (Type formatType)


An object that specifies the type of format object to return.


An instance of the object specified by formatType, if the IFormatProvider implementation can supply that type of object; otherwise, null.


IFormatProvider.GetFormat(Type) is a callback method that formatting and parsing methods invoke to retrieve information about the format of the input string in parsing operations or the format of the output string in formatting operations. In the formatType parameter, the formatting or parsing method passes the type of object it requires to perform its operation. If the IFormatProvider implementation can supply this formatting or parsing object, it returns that object. If not, it returns null.

For example, in the call to the int.ToString(IFormatProvider) method, the method argument is an IFormatProvider object that provides information about how the string representation of the current integer instance might be formatted. When the runtime executes the method, it calls the IFormatProvider object's IFormatProvider.GetFormat(Type) method and passes it a Type object that represents the System.Globalization.NumberFormatInfo type. If the IFormatProvider object can supply a System.Globalization.NumberFormatInfo object, it returns that object. If it cannot supply an object of that type, it returns null.

You can implement the IFormatProvider interface and the IFormatProvider.GetFormat(Type) method in classes that provide custom formatting or parsing services. The IFormatProvider implementation is then passed as an argument to any overload of a parsing or formatting method that has a parameter of type IFormatProvider, such as string.Format(IFormatProvider, string, Object[]), int.ToString(string, IFormatProvider), or DateTime.Parse(string, IFormatProvider).


Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,