Comparing Properties of Objects in a List
<p>I need to synchronize appointments of an online database and a local database.
That's my code so far:</p>

<pre><code>        List&lt;Appointment&gt; onlineAppointments = new List&lt;Appointment&gt;();
        List&lt;Appointment&gt; localAppointments = new List&lt;Appointment&gt;();
        Appointment appointment01 = new Appointment(new DateTime(2012, 12, 24, 17, 30, 00), new DateTime(2012, 12, 24, 17, 45, 00), name, 123, "comment", 0, "test", 123, 1, DateTime.Now);
        Appointment appointment02 = new Appointment(new DateTime(2012, 12, 24, 17, 30, 00), new DateTime(2012, 12, 24, 17, 45, 00), name, 123, "comment", 0, "test", 123, 1, DateTime.Now);

        onlineAppointments.Add(appointment01);
        localAppointments.Add(appointment02);
</code></pre>

<p>Since I only want to compare some properties of the object I have created an IEqualityComparer:</p>

<pre><code>public class AppointmentEqualityComparer&lt;T&gt; : IEqualityComparer&lt;T&gt; where T : Appointment
{
    #region IEqualityComparer&lt;T&gt; Members

    public bool Equals(T x, T y)
    {
        return (x == null &amp;&amp; y == null) || ((x != null &amp;&amp; y != null) &amp;&amp;
        (x.getAppointmentStart() == y.getAppointmentStart() &amp;&amp;
        x.getAppointmentEnd() == y.getAppointmentEnd())
        );
    }

    /// &lt;/exception&gt;
    public int GetHashCode(T obj)
    {
        if (obj == null)
        {
            throw new ArgumentNullException("obj");
        }

        return obj.GetHashCode();
    }

    #endregion
}
</code></pre>

<p>Unfortunately this does not work:</p>

<pre><code>var comparer = new AppointmentEqualityComparer&lt;Appointment&gt;();    
IEnumerable&lt;Appointment&gt; diffOnlineOffline = onlineAppointments.Except(localAppointments, comparer);
</code></pre>

<p>Meaning diffOnlineOffline is not empty but it should be since both lists contain the same appointment.</p>

<p>Any idea?</p>
