{ independency injection }

TemplifyWith Extension Method

I created a super-simple extension-method for doing class-based token replacement on strings, using reflection. You can just pass a C# object to this function and it will replace tokens matching the object's property values in a straight-forward, easy way.

So, given this class:

class Car 
    public string Name { get; set; }
var car = new Car { Name = "Mazda" };
var message = "Hello [Name]!".TemplifyWith(car);

The resulting string (message) will be "Hello Mazda!"

Here's the code: