C# 反射获取属性GetProperty无效的问题解决方法

时间:2025-01-25 08:09:17

C#当中获取属性有种情况为,该属性没有get和set函数,则该属性非属性,实际为字段。因此需要使用以下方法来获取:

Type type = typeof(YourClass);
string propertyName = "yourField";
const BindingFlags InstanceBindFlags =  |  | ;
while (type != null)
{
    property = (propertyName, InstanceBindFlags);
    if (property != null)
    {
        break;
    }
}
int value = (int)();

以上