Extension Method for Generic Class

Viewed 41633
4 Answers

To extend any class

public static class Extensions
{
    public static T DoSomething<T>(this T obj)
    {
        //...
    }
}

To extend a specific generic class

public static NeedExtension<T> DoSomething<T>(this NeedExtension<T> obj)
{
    //...
}

Yes, but you forgot the this keyword. Look at Queryable that provides all the LINQ operators on collections.

Sure

public static void SomeMethod<T>(this NeedsExtension<T> value) {
  ...
}
Related