Given a C# Type, Get its Base Classes and Implemented Interfaces

前端 未结 5 633
庸人自扰
庸人自扰 2020-12-10 16:48

I\'m working on a game engine in C#. The class I\'m working on is called CEntityRegistry, and its job is to keep track of the many instances of CEntity

5条回答
  •  难免孤独
    2020-12-10 17:27

    Use this code:

    Func> f = ty =>
    {
        var tysReturn = new List();
        if (ty.BaseType != null)
        {
            tysReturn.Add(ty.BaseType);
        }
        tysReturn.AddRange(ty.GetInterfaces());
        return tysReturn;
    };
    

    The function f will take a Type and return a list of its base type plus interfaces.

    Hope it helps.

提交回复
热议问题