2
public class ReflectionBase
    {
        public String ParentProperty1 { get; set; }
        public String ParentProperty2 { get; set; }        
    }

    public class Reflection : ReflectionBase
    {
        public String ChildProperty1 { get; set; }

        public Reflection()
        {
            var property = this.GetType().GetProperties();
        }    
    }

结果:
ParentProperty1
ParentProperty2
ChildProperty1
我需要:
ChildProperty1

当我调用 GetProperties() 它给了我所有当前类属性和基类,但我只需要当前类属性。

任何帮助请...

4

1 回答 1

9

用于BindingFlags.DeclaredOnly忽略继承的成员:

var properties = this.GetType().GetProperties(
    BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
于 2012-04-05T19:45:48.207 回答