我有一个动态类型对象,我想从该对象中获取每个属性的所有值。
dynamic row = ....我正在使用property.GetValue(row, null)抛出一个RuntimeBinderException。如何检索此值?
发布于 2012-08-08 00:51:56
这将遍历所有公共属性
dynamic something = new {id = "1", name = "name"};
Type type = something.GetType();
var properties = type.GetProperties();
foreach (var property in properties)
{
var value = property.GetGetMethod().Invoke(something, null);
Console.WriteLine(string.Format("{0}:{1}", property.Name, value));
}https://stackoverflow.com/questions/11850198
复制相似问题