HB *_*AAM 2 .net c# reflection
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();
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
ParentProperty1
ParentProperty2
ChildProperty1
我需要:
ChildProperty1
当我调用GetProperties()时它给了我所有当前的类属性和基类,但我只需要当前的类属性.
任何帮助请...
使用BindingFlags.DeclaredOnly忽略继承的成员:
var properties = this.GetType().GetProperties(
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
Run Code Online (Sandbox Code Playgroud)