Let's say I have:
public class RootClass<T>
{
public virtual T GetOne()
{
return default(T);
}
}
and
public class MiddleClass<T> : RootClass<MiddleClass<T>>
{
// A bunch of additional functionality
}
and
public class ChildClass : MiddleClass<ChildClass>
{
// Even more additional functionality
}
and I want to create the effect of this in ChildClass:
public override ChildClass GetOne()
{
// do some extra stuff
return base.GetOne();
}
so that ultimately when I'm using a ChildClass in a client class the return
type of GetOne() is untuitive and doesn't have to be cast (the point of the
generics in the first place).
I get this error on ChildClass.GetOne():
Error 1 'GenericsLibrary.ChildClass.GetOne()': return type must be
'GenericsLibrary.MiddleClass<GenericsLibrary.Child Class>' to match
overridden member
'GenericsLibrary.RootClass<GenericsLibrary.MiddleC lass<GenericsLibrary.ChildClass>>.GetOne()'
E:\Development\Projects\TempJunk\GenericsTest\Gene ricsLibrary\ChildClass.cs
10 30 GenericsLibrary
How do I accomplish what I want, or what am I misunderstanding about the use
of generics?