I\'ve been reading Albaharis\' \"C# 5.0 in A Nutshell\" and I\'ve encountered this in Generics section and it is said to be legal:
class Bar where T
It means that T must inherit from Person.
This is a typical way to create type-specific methods or properties or parameters in the base class, specific to the actual descendant.
For instance:
public abstract class Base where T : Base, new()
{
public static T Create()
{
var instance = new T();
instance.Configure(42);
return instance;
}
protected abstract void Configure(int value);
}
public class Actual : Base
{
protected override void Configure(int value) { ... }
}
...
Actual a = Actual.Create(); // Create is defined in Base, but returns Actual