Original Post
I have a class and some code that tests is My problem is, that when the t == null is executed the operator == is invoked, which is fine, but inside the operator I test for null again, which invokes the operator again, resulting in an infinite loop. I wonder why this isn't working, while the == operator in the System.Delegate class works the same way, and it works there Sorry for my bad english.
class Test
{
float a;
public static bool operator ==(Test t1, Test t2)
{
if (t1 == null)
return t2 == null;
return t1.Equals(t2);
}
public static bool operator !=(Test t1, Test t2)
{
if (t1 == null)
return t2 != null;
return !t1.Equals(t2);
}
public override bool Equals(object obj)
{
Test t = obj as Test;
if(t == null)
return false;
return this.a == t.a;
}
}
Test t = new Test();
bool b = t == null;
public static bool operator ==(Delegate d1, Delegate d2)
{
if (d1 == null)
{
return (d2 == null);
}
return d1.Equals(d2);
}