Get value of c# dynamic property via string

前端 未结 11 1741
孤城傲影
孤城傲影 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:26

    To get properties from dynamic doc when .GetType() returns null, try this:

    var keyValuePairs = ((System.Collections.Generic.IDictionary)doc);
    var val = keyValuePairs["propertyName"].ToObject;
    

提交回复
热议问题