J
Jakob Lithner
I have a custom generic comparer like this:
internal class SyncItemComparer : IEqualityComparer<ISyncItem>
{
public bool Equals(ISyncItem x, ISyncItem y)
{
return x.GlobalID.Equals(y.GlobalID);
}
public int GetHashCode(ISyncItem obj)
{
return obj.GlobalID.GetHashCode();
}
}
Then i try to use it in this method:
void Sync<ISyncItem>(IEnumerable<ISyncItem> masterItems,
IEnumerable<ISyncItem> clientItems)
{
var comparer = new SyncItemComparer();
foreach (var master in masterItems)
{
if(clientItems.Contains<ISyncItem>(master, comparer))
{
}
}
}
The compiler warns on the Contains method:
Argument type 'MyApp.Business.Comparers.SyncItemComparer' is not assignable
to 'System.Collections.Generic.IEqualityComparer<ISyncItem>`
But the SyncItemComparer implements
System.Collections.Generic.IEqualityComparer<ISyncItem>!
It is very late and I must be blind to something ......
internal class SyncItemComparer : IEqualityComparer<ISyncItem>
{
public bool Equals(ISyncItem x, ISyncItem y)
{
return x.GlobalID.Equals(y.GlobalID);
}
public int GetHashCode(ISyncItem obj)
{
return obj.GlobalID.GetHashCode();
}
}
Then i try to use it in this method:
void Sync<ISyncItem>(IEnumerable<ISyncItem> masterItems,
IEnumerable<ISyncItem> clientItems)
{
var comparer = new SyncItemComparer();
foreach (var master in masterItems)
{
if(clientItems.Contains<ISyncItem>(master, comparer))
{
}
}
}
The compiler warns on the Contains method:
Argument type 'MyApp.Business.Comparers.SyncItemComparer' is not assignable
to 'System.Collections.Generic.IEqualityComparer<ISyncItem>`
But the SyncItemComparer implements
System.Collections.Generic.IEqualityComparer<ISyncItem>!
It is very late and I must be blind to something ......