繁体   English   中英

property.GetValue(dynamictype,null)抛出RuntimeBinderException

[英]property.GetValue(dynamictype,null) throw RuntimeBinderException

我有一个动态类型的对象,我想从该对象获取每个属性的所有值。

dynamic row = ....

我正在使用property.GetValue(row, null)抛出RuntimeBinderException。 如何获取该值?

这将遍历所有公共财产

    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));
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM