KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a good reference implementation for IFormattable ? I plan to have at least one custom IFormatProvider for my object, and I want to make sure that the wiring is correct for the different possible parameter sets passed to IFormattable.ToString(string, IFormatProvider) . What I have so far: public class MyDataClass : IFormattable { /// <seealso cref="IFormattable.ToString(string, IFormatProvider)"/> public string ToString(string format, IFormatProvider formatProvider) { ICustomFormatter formatter = (ICustomFormatter)formatProvider.GetFormat(typeof(ICustomFormatter)); return formatter.Format(format, this, formatProvider); } } But it seems like there are other potential situations that should be covered, i.e.: If formatProvider is null, should I fall back to this.ToString() ? If formatProvider.GetFormat(typeof(ICustomFormatter)) returns null , is there a particular exception I should throw? Any blog posts / code samples / MSDN references are appreciated.
Tags (comma-separated)
Save Edits
Cancel