![]() ![]() You can also use IFormatProvider for a way of passing arbitrary culture objects - through the IFormatProvider. As long as they implement IFormatProvider, and return objects they're asked for, you can bypass the built-in cultures. The value of IFormatProvider is that you create your own culture objects. To get a NumberFormatInfo from an IFormatProvider: NumberFormatInfo format = NumberFormatInfo.GetInstance(provider) To get a DateTimeFormatInfo from an IFormatProvider: DateTimeFormatInfo format = DateTimeFormatInfo.GetInstance(provider) There's also inside knowledge that any IFormatProvider interface is likely being implemented by a class that descends from CultureInfo, or descends from DateTimeFormatInfo, so you could cast the interface directly: CultureInfo info = provider as CultureInfo ĭateTimeFormatInfo dtfi = provider as DateTimeFormatInfo Īll that hard work has already been written for you: ![]() The way it would normally work is you ask the IFormatProvider to give you a DateTimeFormatInfo object: DateTimeFormatInfo format įormat = (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatInfo)) The two commonly available culture objects that an IFormatProvider can be queried for are: The interface is a gateway for a function to get a set of culture-specific data from a culture. CultureInfo.CreateSpecificCulture("de-CA") //German (Canada).The IFormatProvider interface is normally implemented for you by a CultureInfo class, e.g.: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |