genericは結構エロイ
src: class A<T> where T : A<T> { static A() { Console.WriteLine("init:" + typeof(T).Name); } } class AA : A<AA> { } class BB : A<BB> { } class CC : A<Program> { } //err! class Program { static void Main(string[] args) { AA a = new AA(); BB b = new BB(); } } display: init:AA init:BB
なんてコードも難なく通る。こいつは使えるぜ!
制約条件のあたりがトリッキー。ぐるぐる。