Yesterday, I blogged about my new .NET string expansion library called Expansive.
Today, I made some key changes to, hopefully, make it easier to use and more flexible by providing 4 token style format providers out of the box.
- Removed the startToken and endToken delimiters that could be set by the consumer as this was unreliable
- Added 4 new Token Style Formats to pick from:
- MvcRoute Style “{token}” (default)
- Razor Style “@token” or “@(token)”
- NAnt Style “${token}”
- MSBuild Style “$(token)”
So, the following are all valid:
// MvcRoute-Style (default) var mvcRouteStyleString = "Hello, {FirstName}".Expand(new { FirstName = "John" }); // Razor-Style Expansive.DefaultTokenStyle = TokenStyle.Razor; var razorStyleString = "Hello, @FirstName".Expand(new { FirstName = "John" }); // NAnt-Style Expansive.DefaultTokenStyle = TokenStyle.NAnt; var nantStyleString = "Hello, ${FirstName}".Expand(new { FirstName = "John" }); // MSBuild-Style Expansive.DefaultTokenStyle = TokenStyle.MSBuild; var msBuildStyleString = "Hello, $(FirstName)".Expand(new { FirstName = "John" }); // all return "Hello, John"
You can also specify the TokenStyle on the call to Expand() such as:
var expandedString = "Hello, @FirstName".Expand(new { FirstName = "John" }, TokenStyle.Razor);
The addition of TokenStyle makes the API a little cleaner and provide 4 popular token formats.
You can of course add your own by grabbing the source on GitHub and opening the hood.
Enjoy!