I have some classes that don't implement a certain interface but structurally comply to that interface.
interface IFoo {
void method();
}
class Bar { // does not implement IFoo
public void method() {...}
}
Now, I could write a wrapper around those classes that simply delegate to the wrapped class
class BarWrapper : IFoo {
Bar bar = new Bar();
public void method()
{
bar.method();
}
}
But that's lots of tedious work. Can those wrapper classes somehow be generated automatically? Something like:
IFoo foo = CreateWrapper<IFoo>(new Bar());
I'm sure you could do this with Reflection.Emit but I've never used that and it doesn't look very easy at first glance.
Is there an easier way or is there perhaps a library that already implements this?