Get value of c# dynamic property via string

前端 未结 11 1742
孤城傲影
孤城傲影 2020-11-27 11:12

I\'d like to access the value of a dynamic c# property with a string:

dynamic d = new { value1 = \"some\", value2 = \"random\", value3 = \"value\"

11条回答
  •  臣服心动
    2020-11-27 11:43

    d.GetType().GetProperty("value2")

    returns a PropertyInfo object.

    So then do

    propertyInfo.GetValue(d)
    

提交回复
热议问题