I'd make the item type of the HashSet<T>
a class that only contains the data that you base the equality test on. At the moment you are trying to make a DeviceClass
compare equal to an ActualDevice
which seems odd.
My understanding is that you want to test whether an ActualDevice
is associated with one of many DeviceClass
'es. You could do it like this:
class DeviceClassKey : IEquatable<DeviceClassKey> {
//Data members here
int DeviceClassID; /* just an example */
public static DeviceClassKey FromDeviceClass(DeviceClass dc) { return ...; }
public static DeviceClassKey FromActualDevice(ActualDevice ad) { return ...; }
//add equality members here
}
And now you add members to the set like this:
HashSet<DeviceClassKey> items = ...;
DeviceClass dc = ...;
items.Add(DeviceClassKey.FromDeviceClass(dc));
And you test membership like this:
HashSet<DeviceClassKey> items = ...;
ActualDevice ad = ...;
var isMember = items.Contains(DeviceClassKey.ActualDevice(ad));
I might have missed some requirement of yours but this technique can probably be extended to cover it.