Reputation: 113
Consider the sealed framework class "WorkItem" (MSDN-description)
I would like to extend this sealed class so I can write extension methods of the class e.g. I could write:
workitem.ReadWrite();
Is this possible to implement, if so how could it be done?
Upvotes: 0
Views: 1101
Reputation: 2927
It is very much possible to add extension methods to sealed
classes. You can simply create an extension method for a sealed
class like a concrete
class.
You can write like this for your class, Also you need to include the assembly
and use the namespace
of the Extensions class where you will be using the method.
public static class Extensions
{
public static void ReadWrite(this WorkItem item)
{
// Do your code
}
}
Upvotes: 1
Reputation: 1937
Example of Extension Method:
public static class WorkItemExtensions
{
public static void ReadWrite(this WorkItem objRef)
{
// Do things you need here
}
}
Upvotes: 2