{ 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:

Human Friendly File-size Extension Method

I am sharing some cool extension methods I have picked up or created along the way -- here is one that comes in handy if dealing with files.

This will output the double file-size value in Bytes, KB, MB and GB.