I'm building a hierarchical collection class that orders magnetic resonance images spatially and arranges them into groupings based on the various acquisition parameters that were used to generate them. The specific method used to perform the grouping is provided by the user of the class. I've abstracted out the relevant features in the sample code below. For the IEquatable<MyClass>
implementation, I'd like to be able to compare the _myHelperDelegate
attributes of two MyClass
instances to determine if both delegates point to the same piece of code. The (_myHelperDelegate == other._myHelperDelegate)
clause in the if statement below is clearly the wrong way to go about doing this (it fails to compile, giving the error "Method name expected"). My question is, is there a way to compare two delegates to determine if they reference the same piece of code? If so, how do you do that?
public class MyClass : IEquatable<MyClass>
{
public delegate object HelperDelegate(args);
protected internal HelperDelegate _myHelperDelegate;
public MyClass(HelperDelegate helper)
{
...
_myHelperDelegate = helper;
}
public bool Equals(MyClass other)
{
if (
(_myHelperDelegate == other._myHelperDelegate) &&
(... various other comparison criteria for equality of two class instances... )
)
return true;
return false;
}
}
Equals()
method (msdn.microsoft.com/en-us/library/99bthb1z(v=VS.90).aspx), did you try that? – Runner