C#當中獲取屬性有種情況爲,該屬性沒有get和set函數,則該屬性非屬性,實際爲字段。因此需要使用以下方法來獲取:
Type type = typeof(YourClass);
string propertyName = "yourField";
const BindingFlags InstanceBindFlags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
while (type != null)
{
property = type.GetField(propertyName, InstanceBindFlags);
if (property != null)
{
break;
}
}
int value = (int)property.GetValue(BuildingWindow.instance);
以上