C# extension methods

How to write extension methods
=======================

Extension methods are written as a static class with static method. We pass the parameter as "this targetmethod". The target method is what are extending/overriding.

Example:

public static class ConfigurationExtensions
{
    public static bool IsLoaded(this IConfiguration config)
    {
       return config.AsEnumberable().Any();
     }
}



Pro Tip: Humanizer library helps to format strings. Like "14 minutes ago"

Courtesy: https://github.com/sixeyed/megacorp-extensions/blob/master/src/Extensions.System/DateTimeExtensions.cs




Comments