提交 0fd8571e 编写于 作者: D David Poeschl

Update EventMap.Registry.HasHandler to use .Equals

This fixes internal TFS issue #1161343

The event handlers being tracked by EventMap may not be reference equal,
so use .Equals to compare them instead of ==. This fixes an event
handler leak and matches the equals behavior from before commit
7cda9431, when we used List.Remove.

This change also adds some more careful null handling for when a
Registry<TEventHandler> has a null handler.
上级 7a04ebfe
......@@ -116,12 +116,27 @@ public void Invoke(Action<TEventHandler> invoker)
public bool HasHandler(TEventHandler handler)
{
return this.handler == handler;
return handler.Equals(this.handler);
}
public bool Equals(Registry<TEventHandler> other)
{
return other != null && other.handler == this.handler;
if (other == null)
{
return false;
}
if (other.handler == null && this.handler == null)
{
return true;
}
if (other.handler == null || this.handler == null)
{
return false;
}
return other.handler.Equals(this.handler);
}
public override bool Equals(object obj)
......@@ -131,7 +146,7 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
return this.handler.GetHashCode();
return this.handler == null ? 0 : this.handler.GetHashCode();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册