Convert Dictionary To Anonymous Object?

后端 未结 7 1350
挽巷
挽巷 2020-11-27 16:33

First, and to make things clearer I\'ll explain my scenario from the top:

I have a method which has the following signature:

public virtual void Send         


        
相关标签:
7条回答
  • 2020-11-27 17:01

    I tried to do this in one statement with a reduce function (Aggregate in Linq). The code below does the same as the accepted answer:

    var dict = new Dictionary<string, object> { { "Property", "foo" } };
    dynamic eo = dict.Aggregate(new ExpandoObject() as IDictionary<string, Object>,
                                (a, p) => { a.Add(p.Key, p.Value); return a; });
    string value = eo.Property;
    
    0 讨论(0)
提交回复
热议问题