Get properties from derived class in base class

前端 未结 7 2230
面向向阳花
面向向阳花 2021-02-09 07:02

How do I get properties from derived class in base class?

Base class:

public abstract class BaseModel {
    protected static readonly Dictionary

        
7条回答
  •  迷失自我
    2021-02-09 07:28

    If both classes are in the same assembly, you can try this:

    Assembly
        .GetAssembly(typeof(BaseClass))
        .GetTypes()
        .Where(t => t.IsSubclassOf(typeof(BaseClass))
        .SelectMany(t => t.GetProperties());
    

    This will give you all the properties of all the subclasses of BaseClass.

提交回复
热议问题