Travis and I were kicking around this idea. It's either already been done and it's a great idea, it's a good idea and no one has bothered, or it's stupid because _______.
We use a lot of "Domain Objects" like say, "public class Person." Why not have a "aggregated" ToString override like this:
Person p = new Person("Scott","Hanselman",new DateTime(1974,1,22);//blah blah blahstring foo = p.ToString("My name is {FirstName} {LastName} and my birthday is {Birthdate:MM/dd/yyyy}");
Is this stupid? Would it gain you anything over:
string foo = String.Format("My name is {0} {1} and my birthday is {2:MM/dd/yyyy}",p.FirstName,p.LastName,p.BirthDate);
I've got it half done, but I wanted to know your thoughts before I finish it.
My thinking is that, even though it'd be slow (Reflection) it's useful for these reasons:
Am I smoking crack?
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.