Comparing dynamic objects in C#

前端 未结 6 2305
不知归路
不知归路 2021-02-13 04:08

What is the best way to compare two arbitrary dynamic objects for equality? For example these two objects.

I.e.

dynamic obj1 = new ExpandoObject();
obj1.         


        
6条回答
  •  执念已碎
    2021-02-13 04:10

    Expando Objects are useable as an IDictonary so you should be able to use that.

    Something like

    Assert.AreEqual((IDictonary(object, string))obj1, (IDictonary(object, string))obj2); 
    

    Edit the AreEqual won't work.

    But you could try comparing the two dictionaries fairly simply.

提交回复
热议问题