OK, I've been going through some of the newer C# features and I've ended up with an interface and a genericised extension method (with type inference) on the interface.
public interface IMyInterface
{
int SomeProperty {get; set;}
void DoSomething(int);
}
public static class InterfaceExtender
{
public static T ExtensionMethod<T>(this T implementation, int i) where T : IMyInterface
{
implementation.DoSomething(i + implemenatation.SomeProperty);
return implementation
}
}
So now in code you can do
IMyInterface item = new InterfaceImplementation();
item.ExtensionMethod().SomeProperty = 5;
(note, I'm using a flow syntax in the extension property).
So the question: are there any benefits to this over just using an abstract class with the extension method built-in?
Herbie
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.