ICustomFormatter and IFormattable
-
I am looking at these two different interefacing sytems within the framework, ICustomFormatter and IFormattable, and I trying to digest the pros and cons of each. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcompositeformatting.asp[^] Discusses some of the ordering differences, but I would like your opinions! What is the differnce in this two interfaces? do you need to investigate an online backup[^] company
-
I am looking at these two different interefacing sytems within the framework, ICustomFormatter and IFormattable, and I trying to digest the pros and cons of each. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcompositeformatting.asp[^] Discusses some of the ordering differences, but I would like your opinions! What is the differnce in this two interfaces? do you need to investigate an online backup[^] company
ICustomFormatter
lets you define entirely custom formatter for your object. You don't have to impement or specify which standard formatting codes, like G or N, that your formatter supports because you're providing the ENTIRE formatting implementation yourself, including parsing custom formatting commands in the format string (object.ToString("customFormattingCodes"). You're extending the standard set of codes with your own. TheIFormattable
interface says that you're not extending the existing set of foratting codes, but just providing custom implementations for the standard set of codes, with respect to the current culture. At a minimum, your code must support the standard formatting code "G", or General format. You can supply custom formatters for any and all of the standard formats. For example, consider the "C", Currency format. There is a standard implementation for a floating point number and returns a string representation of the number, formatted to what is specified in the current culture. You could implement your own, similar functionality on any of your own custom objects, even those that don't directly represent a number. Your custom formatter for Currency would respond to the standard format string "C", like this:myCustomObject.ToString("C")
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome