How do you get the Value of a property from PropertyInfo?

后端 未结 4 1206
野性不改
野性不改 2020-12-16 09:58

I\'ve got an object that has a collection of properties. When I get the specific entity I can see the field I\'m looking for (opportunityid) and that it\'s

4条回答
  •  旧巷少年郎
    2020-12-16 10:15

    Use PropertyInfo.GetValue(). Assuming your property has the type Guid? then this should work:

    attrGuid = ((System.Guid?)info.GetValue(attr, null)).Value;
    

    Note that an exception will be thrown if the property value is null.

提交回复
热议问题