public string aa;
public string bb;
These are not properties. Properties are defined such as:
public string Aa
{
get;
set;
}
For more information, look up the official documentation on MSDN.
Once you've made the corrections to your classes A
and B
, you will be able to use :
var classProperties = typeof(B).GetTypeInfo().DeclaredProperties;
For properties defined within the class B, and :
var allProperties = typeof(B).GetRuntimeProperties();
For properties that are defined within the class and in its inheritance tree; i.e. properties that are actually accessible at runtime (therefore the name of the method).
If you don't want to change the public
fields to properties (but you definitely should), use the GetRuntimeFields
method on typeof(B)
and DeclaredMembers
on typeof(B).GetTypeInfo()
for similar behaviour.