circular generic type parameters

前端 未结 2 984
时光说笑
时光说笑 2020-12-09 10:15

I have 2 generic classes, a BaseComponent Class, and a BaseManager class.

They\'re both abstract and are intended to be made concrete.

2条回答
  •  伪装坚强ぢ
    2020-12-09 10:41

    It sounds like you might want to have two generic type parameters:

    public abstract class BaseManager
        where TComponent : BaseComponent
        where TManager : BaseManager
    public abstract class BaseComponent
        where TComponent : BaseComponent
        where TManager : BaseManager
    

    Yes, it's smelly - but that's the sort of thing I've done in Protocol Buffers.

    So then you'd have:

    public class PhysicsManager : BaseManager
    
    public class PhysicsComponent : BaseComponent
    

提交回复
热议问题