title: Linq Except with custom IEqualityComparer
body: <p>I am trying to find the difference between two generic lists, as in the example below. 
  Even though t1 and t2 contain the same properties, they are not the same object, so I have need to implement an IEqualityComparer.</p>
  
  <p>This appears to be working with this example, but the real class has several other properties and I also need to do the same with a few other class.</p>
  
  <p>So I was wondering if I am re-inventing the wheel?</p>
  
  <p>Is there an easier method of comparing all the properties of two objects? At the moment, I really only need to cope with class containing simple types, but it would be nice I have a  comparer that worked with classes that contains instances of other classes.</p>
  
  <pre><code>void Main()
  {
      var t1 = new Sizes { Name = "Test" , Size = 1} ;
      var t2 = new Sizes { Name = "Test" , Size = 1} ;
  
      var list1 = new List&lt;Sizes&gt;();
      var list2 = new List&lt;Sizes&gt;();
      list1.Add(t1);
      list2.Add(t2);
  
      var differences = list2.Except(list1 , new SizesComparer());    
      // differences should be empty.
  }
  
  
  public class Sizes  
  {
      public string Name { get;  set; }
      public int    Size { get;  set; }
  }
  
  public class SizesComparer : IEqualityComparer&lt;Sizes&gt;   
  {
      bool IEqualityComparer&lt;Sizes&gt;.Equals(Sizes x, Sizes y)
      {            
          return (x.Name.Equals(y.Name) &amp;&amp; x.Size.Equals(y.Size));        
      }
  
      int IEqualityComparer&lt;Sizes&gt;.GetHashCode(Sizes obj)
      {
          if (Object.ReferenceEquals(obj, null))
              return 0;               
  
          return obj.Name.GetHashCode() + obj.Size;       
      }
  }
  </code></pre>