How can I create a JsonPatchDocument from comparing two c# objects?

前端 未结 3 1777
醉话见心
醉话见心 2021-01-31 19:51

Given I have two c# objects of the same type, I want to compare them to create a JsonPatchDocument.

I have a StyleDetail class defined like this:

public         


        
3条回答
  •  醉话见心
    2021-01-31 20:52

    You could use my DiffAnalyzer. It's based on reflection and you can configure the depth you want to analyze.

    https://github.com/rcarubbi/Carubbi.DiffAnalyzer

    var before = new User { Id = 1, Name="foo"};
    var after= new User  { Id = 2, Name="bar"};
    var analyzer = new DiffAnalyzer();
    var results = analyzer.Compare(before, after);
    

提交回复
热议问题