1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-27 20:18:01 +02:00
Beef/BeefLibs/corlib/src/Delegate.bf

69 lines
1.2 KiB
Beef
Raw Normal View History

2019-08-23 11:56:54 -07:00
namespace System
{
class Delegate : IHashable
2019-08-23 11:56:54 -07:00
{
void* mFuncPtr;
void* mTarget;
public static bool Equals(Delegate a, Delegate b)
{
if (a === null)
return b === null;
return a.Equals(b);
}
public virtual bool Equals(Delegate val)
{
if (this === val)
2019-08-23 11:56:54 -07:00
return true;
if (val == null)
2019-08-23 11:56:54 -07:00
return false;
return (mFuncPtr == val.mFuncPtr) && (mTarget == val.mTarget);
2019-08-23 11:56:54 -07:00
}
public Result<void*> GetFuncPtr()
{
if (mTarget != null)
return .Err; //("Delegate target method must be static");
return mFuncPtr;
}
public void* GetTarget()
{
return mTarget;
}
public void SetFuncPtr(void* ptr, void* target = null)
{
mTarget = target;
mFuncPtr = ptr;
}
2019-10-05 10:25:07 -07:00
protected override void GCMarkMembers()
{
// 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);
}
2019-08-23 11:56:54 -07:00
}
2020-05-08 07:10:35 -07:00
delegate void Action();
2019-08-23 11:56:54 -07:00
struct Function : int
{
}
}