Reflection: different ways to retrieve property value
Posted
by jules
on Stack Overflow
See other posts from Stack Overflow
or by jules
Published on 2010-03-03T11:52:36Z
Indexed on
2010/04/03
10:23 UTC
Read the original article
Hit count: 189
c#2.0
|reflection
I'm retrieving an IEnumerable list of properties via following code:
BindingFlags bindingFlag = BindingFlags.Instance | BindingFlags.Public;
var dataProperties = typeof(myParentObject).GetProperties(bindingFlag);
Then I'm iterating through the list and retrieving the value for each property.
I've come across two different approaches to doing this, and just wondered what the difference is between them:
1)
object propertyValue = property.GetGetMethod().Invoke(myObject, null);
2)
object propertValue = property.GetValue(myObject, null)
© Stack Overflow or respective owner