How to find out if property is inherited from a base class or declared in derived?

后端 未结 3 861
野的像风
野的像风 2021-02-05 07:28

I have a class that is derived from an abstract class. Getting a type of a derived class I want to find out which properties are inherited from abstract class and which were dec

3条回答
  •  故里飘歌
    2021-02-05 08:06

    This may helps:

    Type type = typeof(MsClass);
    
    Type baseType = type.BaseType;
    
    var baseProperties = 
         type.GetProperties()
              .Where(input => baseType.GetProperties()
                                       .Any(i => i.Name == input.Name)).ToList();
    

提交回复
热议问题