Recently I found myself in a situation where I wanted to format a string using a named format string, rather than a positional one. Ignore for the moment the issue on whether this is a good idea or not, just trust me that I?ll be responsible with it. The existing String.Format method, for example, formats values according to position. string s = string .Format( "{0} first, {1} second" , 3.14, DateTime.Now); But what I wanted was to be able to use the name of properties/fields, rather than position like so: var someObj = new {pi = 3.14, date = DateTime.Now}; string s = NamedFormat( "{pi} first, {date} second" , someObj); Looking around the internet, I quickly found three implementations mentioned in this StackOverflow question...(read more) ...
Go to the complete details ...