Consider the following class structure:
public class Foo<T> { public virtual void DoSomething() { } public class Bar<U> where U : Foo<T>, new() { public void Test() { var blah = new U(); blah.DoSomething(); } } } public class Baz { } public class FooBaz : Foo<Baz> { public override void DoSomething() { } }
When I move on to using a nested class, I have something like the following:
var x = new FooBaz.Bar<FooBaz>();
It seems redundant to specify it twice. How would I create my class structure so that I can do this:
var x = new FooBaz.Bar();
Should there be some way in the where clause of a nested class to say that U is always a parent? How?
Update: Added methods for DoSomething () above to consider some comments. It is important that when I call DoSomething, it accesses an overridden version. If I just use Foo instead of U, then the underlying implementation is called instead.
source share