mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 17:08:00 +02:00
Delegate comparison expansion, hashable, == operator
This commit is contained in:
parent
9dcafb7db8
commit
a3a8bfa40c
8 changed files with 157 additions and 18 deletions
|
@ -1,17 +1,24 @@
|
|||
namespace System
|
||||
{
|
||||
class Delegate
|
||||
class Delegate : IHashable
|
||||
{
|
||||
void* mFuncPtr;
|
||||
void* mTarget;
|
||||
|
||||
public static bool Equals(Delegate a, Delegate b)
|
||||
{
|
||||
if ((Object)a == (Object)b)
|
||||
if (a === null)
|
||||
return b === null;
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public virtual bool Equals(Delegate val)
|
||||
{
|
||||
if (this === val)
|
||||
return true;
|
||||
if ((Object)a == null || (Object)b == null)
|
||||
if (val == null)
|
||||
return false;
|
||||
return (a.mFuncPtr == b.mFuncPtr) && (a.mTarget == b.mTarget);
|
||||
return (mFuncPtr == val.mFuncPtr) && (mTarget == val.mTarget);
|
||||
}
|
||||
|
||||
public Result<void*> GetFuncPtr()
|
||||
|
@ -37,6 +44,19 @@ namespace System
|
|||
// Note- this is safe even if mTarget is not an object, because the GC does object address validation
|
||||
GC.Mark(Internal.UnsafeCastToObject(mTarget));
|
||||
}
|
||||
|
||||
public int GetHashCode()
|
||||
{
|
||||
return (int)mFuncPtr;
|
||||
}
|
||||
|
||||
[Commutable]
|
||||
public static bool operator==(Delegate a, Delegate b)
|
||||
{
|
||||
if (a === null)
|
||||
return b === null;
|
||||
return a.Equals(b);
|
||||
}
|
||||
}
|
||||
|
||||
delegate void Action();
|
||||
|
|
|
@ -418,7 +418,7 @@ namespace System
|
|||
{
|
||||
using (sMonitor.Val.Enter())
|
||||
{
|
||||
if (sErrorHandlers.Remove(handler))
|
||||
if (sErrorHandlers.RemoveStrict(handler))
|
||||
return .Ok;
|
||||
}
|
||||
return .Err;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue