C# WinRt中的反射获取继承类的参数

C# WinRt中的反射获取继承类的参数,c#,inheritance,reflection,windows-runtime,C#,Inheritance,Reflection,Windows Runtime,我有两个类,我想使用反射 public Class A { public string aa { get; set; } public string bb { get; set; } ... } public Class B: A {} 当我试图得到一个B对象的属性时,我没有得到任何属性 TypeInfo b = typeof(B).GetTypeInfo(); IEnumerable<PropertyInfo> pList = b.DeclaredPro

我有两个类,我想使用反射

public Class A
{
    public string aa { get; set; }
    public string bb { get; set; }
    ...
}

public Class B: A {}
当我试图得到一个B对象的属性时,我没有得到任何属性

TypeInfo b = typeof(B).GetTypeInfo();
IEnumerable<PropertyInfo> pList = b.DeclaredProperties;  
忽略PropertyInfo,如果我尝试获取对象的属性,它也会起作用


当我读取对象的属性时,
getType().GetTypeInfo()
getType().GetRuntimeProperties()
之间有什么区别

public string aa;
public string bb;
这些不是财产。属性的定义如下:

public string Aa
{
    get;
    set;
}
有关更多信息,请查阅

在对类
A
B
进行更正后,您将能够使用:

var classProperties = typeof(B).GetTypeInfo().DeclaredProperties;
对于B类中定义的属性,以及:

var allProperties = typeof(B).GetRuntimeProperties();
对于在类及其继承树中定义的属性;i、 e.在运行时实际可访问的属性(因此是方法的名称)


如果您不想将
public
字段更改为属性(但您肯定应该这样做),请使用
typeof(B)
上的
GetRuntimeFields
方法和
typeof(B)上的
DeclaredMembers
上的
GetTypeInfo()
进行类似操作。

“getType().GetTypeInfo()和getType()之间有什么区别?”.GetRuntimeProperties()“=>这是两种截然不同的方法。如果您正在谈论
TypeInfo
类上的
DeclaredProperties
属性,我已经解释了它与
GetRuntimeProperties
之间的区别。“找到解决方案,疑问依然存在”=>如果您对该主题有更多问题,请打开另一个问题;如果我的答案解决了你的问题,请将其标记为答案。
var allProperties = typeof(B).GetRuntimeProperties();