That won't work, you can do it this way:
class MdlObject
{
public void Insert(dynamic anObject)
{
var propertyInfos = anObject.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
MessageBox.Show(propertyInfo.Name);
}
MessageBox.Show(anObject.Name);
MessageBox.Show(anObject.Id.ToString());
}
}
Or do this:
foreach (var propertyInfo in propertyInfos)
{
MessageBox.Show(propertyInfo.Name);
MessageBox.Show(propertyInfo.GetValue(anObject, null).ToString());
}