title: How to compare two objects when you can't override Equals?
body: <p>I have an object <code>modelNoBend</code> of type <code>CalculationModel</code> and I have serialized it into a JSON and saved it in a <code>.txt</code> file using the below:</p>
  <pre><code>private static void GenerateTextFileNoBend(string path, CalculationModel model)
  {
     if (!File.Exists(path)) {
        using (var file = File.CreateText(path + &quot;noBend.txt&quot;)) {
           var json = JsonConvert.SerializeObject(model);
           file.Write(json);
        }
     }
  }
  </code></pre>
  <p>Then, I wanted to deserialize that JSON and check with the original object whether they are the same or not.</p>
  <pre><code>static void Main(string[] args)
  {
     GenerateTextFileNoBend(path, modelNoBend); 
  
     var jsonText = File.ReadAllText(@&quot;D:\5113\noBend.txt&quot;);
  
     CalculationModel model = JsonConvert.DeserializeObject&lt;CalculationModel&gt;(jsonText);
  
     string one = JsonConvert.SerializeObject(modelNoBend);
     string two = JsonConvert.SerializeObject(model);
  
     if (model.Equals(modelNoBend)) {
        Console.Write(&quot;Yes&quot;);
     }
  
     if (one.Equals(two)) {
        Console.Write(&quot;Yes&quot;);
     }
  
    }
  </code></pre>
  <blockquote>
  <pre><code>  if (model.Equals(modelNoBend)) - False
    if (one.Equals(two)) - True
  </code></pre>
  </blockquote>
  <p>If I compare the two objects, <code>.Equals()</code> returns false. However, if I serialize them both once again and compare the strings, the <code>if</code> goes on the true branch.</p>
  <p>Obviously, something that I have missed out on the last post is that <strong>I can not edit the CalculationModel class</strong>. This means that I can not follow the answers in <a href="https://stackoverflow.com/questions/29599910/object-equals-method-returns-false-on-seemingly-equal-object">this question</a>, since I can not override <code>Equals</code>, nor use something else like <code>IEqualityComparer</code> as it requires the class to implement <code>IComparable</code>.</p>
  <p>Is there any workaround for this, without me having to touch that class?</p>