title: How to compare properties between two objects
body: <p>I have two similar classes : <code>Person</code> , <code>PersonDto</code></p>
  
  <pre><code>public class Person 
  {
      public string Name { get; set; }
      public long Serial { get; set; }
      public DateTime Date1 { get; set; }
      public DateTime? Date2 { get; set; }
  }
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>public class PersonDto
  {
      public string Name { get; set; }
      public long Serial { get; set; }
      public DateTime Date1 { get; set; }
      public DateTime? Date2 { get; set; }
  }
  </code></pre>
  
  <p>I have two objects of both by equal values.</p>
  
  <pre><code>    var person = new Person { Name = null , Serial = 123, Date1 = DateTime.Now.Date, Date2 = DateTime.Now.Date };
      var dto = new PersonDto { Name = "AAA", Serial = 123, Date1 = DateTime.Now.Date, Date2 = DateTime.Now.Date };
  </code></pre>
  
  <p>I need to check value of all properties in two classes by reflection. My final goal is defined difference value of this properties.</p>
  
  <pre><code>    IList diffProperties = new ArrayList();
      foreach (var item in person.GetType().GetProperties())
      {
          if (item.GetValue(person, null) != dto.GetType().GetProperty(item.Name).GetValue(dto, null))
              diffProperties.Add(item);
      }
  </code></pre>
  
  <p>I did this, but result is not satisfactory. Count of <code>diffProperties</code> for result was <code>4</code>but count of my expect was <code>1</code>.</p>
  
  <p>Of course all properties can have null values.</p>
  
  <p>I need to a solution generic.
  What must do I? </p>