public class A{
public Info m_Info = new Info();
Main()
{
Console.WriteLine(m_Info.Property_Count());
}
public class Info{
protected int i_Id;
protected string s_Name;
public int Property_Count(){
System.Reflection.PropertyInfo[] data = this.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
foreach(var item in data)
Console.WriteLine(item.Name);
return data.Length;
}
}
}
I am trying to get private or protected properties~ but data.Length always return 0, sounds like it get nothing, why it?
Your class doesn't have any properties. These:
are fields. You can either change them to properties:
or you can use
GetFields
: