dynamic動態新增 property (轉)

  • 159
  • 0
  • 2018-11-02

dynamic動態新增 property

 

    static void Main(string[] args)
    {
        dynamic expando = new ExpandoObject();
        var p = expando as IDictionary<String, object>;
        p["A"] = "New val 1";
        p["B"] = "New val 2";

        Console.WriteLine(expando.A);
        Console.WriteLine(expando.B);
    }

https://stackoverflow.com/questions/3033410/how-to-set-a-property-of-a-c-sharp-4-dynamic-object-when-you-have-the-name-in-an