Tuesday, June 23, 2009

Get property value without casting to it's original source

Today I had a requirement to check a property value without casting or converting it back to it's source class.

this is one way i foundout doing it..


Type t = element.DataContext.GetType();

foreach (var prop in t.GetProperties())
{
if (prop.Name == "MessageType")
{
string messageType = prop.GetValue(element.DataContext, null).ToString();
break;
}
}

No comments: