C# 指定依赖于其他泛型类的泛型约束

C# 指定依赖于其他泛型类的泛型约束,c#,generics,C#,Generics,我有以下几点: // This part is fine abstract class Attack {} abstract class Unit<A> where A : Attack {} class InstantAttack : Attack {} class Infantry : Unit<InstantAttack> {} // I'm lost here, on this part's syntax: abstract class Controller

我有以下几点:

// This part is fine
abstract class Attack {}

abstract class Unit<A> where A : Attack {}

class InstantAttack : Attack {}
class Infantry : Unit<InstantAttack> {}

// I'm lost here, on this part's syntax:
abstract class Controller<U> where U : Unit {}
// I want the above class to take any kind of Unit, but Unit is a generic class!
这肯定不管用。执行此操作的正确语法是什么?

如下所示:

abstract class Controller<U, A> where U : Unit<A> {}
interface IUnit { }
abstract class Unit<A> : IUnit where A : Attack { }
abstract class Controller<U> where U : IUnit { }
抽象类控制器,其中U:Unit{}
或者像这样:

abstract class Controller<U, A> where U : Unit<A> {}
interface IUnit { }
abstract class Unit<A> : IUnit where A : Attack { }
abstract class Controller<U> where U : IUnit { }
接口IUnit{}
抽象类单元:IUnit,其中A:Attack{}
抽象类控制器,其中U:IUnit{}