“Property set method not found” error during reflection

前端 未结 3 1668
挽巷
挽巷 2021-01-07 16:56

I\'m trying to reflect over some class properties and set them programaticlly, but it looks like one of my PropertyInfo filters isn\'t working:

//Get all pub         


        
3条回答
  •  不要未来只要你来
    2021-01-07 17:23

    From the documentation:

    BindingFlags.SetProperty

    Specifies that the value of the specified property should be set. For COM properties, specifying this binding flag is equivalent to specifying PutDispProperty and PutRefDispProperty.

    BindingFlags.SetProperty and BindingFlags.GetProperty do not filter properties that are missing setters or getters, respectively.

    To check if a property can be set, use the CanWrite property.

    if (pi.CanWrite)
        pi.SetValue(this, valueFromData, null);
    

提交回复
热议问题