I have a base class, with a method, where I would like to use generics to force the coder to use a generic expression on the current class:
public class TestClas
Make the base class itself generic:
public class TestClass<T> where T : TestClass<T>
{
public void DoStuffWithFuncRef(Expression<Func<T, object>> expression)
{
this.DoStuffWithFuncRef(Property<T>.NameFor(expression));
}
}
and derive from it:
public class SubTestClass : TestClass<SubTestClass> {
// ...
}
If you need to have an inheritance hierarchy with a single root, inherit the generic base class from another non-generic version:
public class TestClass { ... }
public class TestClass<T> : TestClass where T : TestClass<T>
Of course you should probably make the base classes abstract.