title: How can I create a JsonPatchDocument from comparing two c# objects?
body: <p>Given I have two c# objects of the same type, I want to compare them to create a JsonPatchDocument.</p>
  
  <p>I have a StyleDetail class defined like this: </p>
  
  <pre><code>public class StyleDetail
      {
          public string Id { get; set; }
          public string Code { get; set; }
          public string Name { get; set; }
          public decimal OriginalPrice { get; set; }
          public decimal Price { get; set; }
          public string Notes { get; set; }
          public string ImageUrl { get; set; }
          public bool Wishlist { get; set; }
          public List&lt;string&gt; Attributes { get; set; }
          public ColourList Colours { get; set; }
          public SizeList Sizes { get; set; }
          public ResultPage&lt;Style&gt; Related { get; set; }
          public ResultPage&lt;Style&gt; Similar { get; set; }
          public List&lt;Promotion&gt; Promotions { get; set; }
          public int StoreStock { get; set; }
          public StyleDetail()
          {
              Attributes = new List&lt;string&gt;();
              Colours = new ColourList();
              Sizes = new SizeList();
              Promotions = new List&lt;Promotion&gt;();
          }
      }
  </code></pre>
  
  <p>if I have two StyleDetail objects</p>
  
  <pre><code>StyleDetail styleNew = db.GetStyle(123);
  StyleDetail styleOld = db.GetStyle(456);
  </code></pre>
  
  <p>I now want to create a JsonPatchDocument so I can send the differences to my REST API... How to do this??</p>
  
  <pre><code>JsonPatchDocument patch = new JsonPatchDocument();
  // Now I want to populate patch with the differences between styleNew and styleOld - how?
  </code></pre>
  
  <p>in javascript, there is a library to do this <a href="https://www.npmjs.com/package/rfc6902" rel="noreferrer">https://www.npmjs.com/package/rfc6902</a></p>
  
  <blockquote>
    <p>Calculate diff between two objects:</p>
    
    <p>rfc6902.createPatch({first: 'Chris'}, {first: 'Chris', last:
    'Brown'});</p>
  
  <pre><code>[ { op: 'add', path: '/last', value: 'Brown' } ]
  </code></pre>
  </blockquote>
  
  <p>but I am looking for a c# implementation</p>