Skip to content

Instantly share code, notes, and snippets.

@jinweijie
Created July 19, 2012 01:15
Show Gist options
  • Save jinweijie/3140106 to your computer and use it in GitHub Desktop.
Save jinweijie/3140106 to your computer and use it in GitHub Desktop.
GetAnonymousObjectValue
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