3 ms·
That's where delegation comes in. You wrap each public method of Foo in another class call MyFoo and then fix the one method you care about. With C# and R# it'
by scarface74 8y ago
That's where delegation comes in. You wrap each public method of Foo in another class call MyFoo and then fix the one method you care about. With C# and R# it's a simple matter of:
Create a new class
Create a private variable:
private Foo _foo
Click on _foo
Resharper menu -> Generate Code -> create Delegating members.
- wvenable 8y agoBut you can't pass that into places that accept Foo because MyFoo isn't of the type Foo so that's a non-starter is most cases. Secondly this code generation solution is just re-implementing inheritance again poorly and with the above mentioned limitation. I fail to see how code generating a proxy is any way better than (or significantly different from) inheritance.
- scarface74 8y agoHopefully the code was written to depend on interfaces and not hard coded types.
- wvenable 8y agoSo if you implement an interface and then use code generation to create proxy from a "parent class", congratulations you just reinvented inheritance. What's the difference?