From Thomas Levesque, a bunch of usefull string extension and a string format extended to fields and properties (use Regex to find named placeholder and Expression compilation to access it).
Supported syntax is less rich (no sub-property, no indexer) than DataBinder solution (like FormatWith 2.0 – String formatting with named variables) but it doesn’t require dependency on System.Web and can be PCL).
thomaslevesque/NString · GitHub.
Edit: We can refer to Fun With Named Formats, String Parsing, and Edge Cases and .Net ObjectFormatter – Using Tokens in a Format String for two other implementations and interesting discussion of how to escape brace and how to proceed. Basically, we have:
- to find {Xxxx}, either Regex or a hand coded parser using a small state machine,
- to evaluate Xxxx against an object instance :
- pure Reflexion to read field or property,
- Expression.Compile to read field or property,
- DataBinder.Eval with a rich syntax but slow and introducing a dependency on System.Web,
- to replace {Xxxx}, either Regex.Replace or using a generated standard String.Format with positional {2} or a manual construction.