Created
July 19, 2012 01:15
-
-
Save jinweijie/3140106 to your computer and use it in GitHub Desktop.
GetAnonymousObjectValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetAnonymousObjectValue( object data, string propName ) | |
{ | |
Type t = data.GetType(); | |
// Get a list of the properties | |
PropertyInfo[] piList = t.GetProperties(); | |
// Loop through the properties in the list | |
foreach(PropertyInfo pi in piList) | |
{ | |
// Get the value of the property | |
object o = pi.GetValue(data, null); | |
// Write out the property information | |
if(pi.Name == propName ) | |
return o.ToString(); | |
} | |
return string.Empty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment