Possible Duplicates:
C# -Generic Extension Method
How do you write a C# Extension Method for a Generically Typed Class
Is it possible to declare extension methods for generic classes?
public class NeedsExtension<T>
{
public NeedsExtension<T> DoSomething(T obj)
{
// ....
}
}
Yes, but you forgot the
this
keyword. Look at Queryable that provides all the LINQ operators on collections.Sure
To extend any class
To extend a specific generic class
How do you write a C# Extension Method for a Generically Typed Class