_dotnet events
This commit is contained in:
@@ -241,6 +241,15 @@ struct NativeFieldDefinitions
|
||||
MFieldAttributes fieldAttributes;
|
||||
};
|
||||
|
||||
struct NativeEventDefinitions
|
||||
{
|
||||
const char* name;
|
||||
void* eventHandle;
|
||||
void* addMethodHandle;
|
||||
void* removeMethodHandle;
|
||||
MMethodAttributes attributes;
|
||||
};
|
||||
|
||||
struct NativePropertyDefinitions
|
||||
{
|
||||
const char* name;
|
||||
@@ -1045,7 +1054,23 @@ const Array<MEvent*>& MClass::GetEvents() const
|
||||
if (_hasCachedEvents)
|
||||
return _events;
|
||||
|
||||
// TODO: implement MEvent in .NET
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedEvents)
|
||||
return _events;
|
||||
|
||||
NativeEventDefinitions* foundEvents;
|
||||
int numEvents;
|
||||
static void* GetClassEventsPtr = GetStaticMethodPointer(TEXT("GetClassEvents"));
|
||||
CallStaticMethod<void, void*, NativeEventDefinitions**, int*>(GetClassEventsPtr, _handle, &foundEvents, &numEvents);
|
||||
_events.SetCapacity(numEvents, false);
|
||||
for (int i = 0; i < numEvents; i++)
|
||||
{
|
||||
const NativeEventDefinitions& definition = foundEvents[i];
|
||||
MEvent* evnt = New<MEvent>(const_cast<MClass*>(this), definition.eventHandle, definition.addMethodHandle, definition.removeMethodHandle, definition.attributes, definition.name);
|
||||
_events.Add(evnt);
|
||||
MCore::GC::FreeMemory((void*)definition.name);
|
||||
}
|
||||
MCore::GC::FreeMemory(foundEvents);
|
||||
|
||||
_hasCachedEvents = true;
|
||||
return _events;
|
||||
@@ -1154,26 +1179,33 @@ void MDomain::Dispatch() const
|
||||
{
|
||||
}
|
||||
|
||||
MEvent::MEvent(MClass* parentClass, void* handle, const char* name)
|
||||
MEvent::MEvent(MClass* parentClass, void* handle, void* addMethodHandle, void* removeMethodHandle, MMethodAttributes attributes, const char* name)
|
||||
: _handle(handle)
|
||||
, _addMethod(nullptr)
|
||||
, _removeMethod(nullptr)
|
||||
, _parentClass(parentClass)
|
||||
, _name(name)
|
||||
, _hasCachedAttributes(false)
|
||||
, _hasAddMonoMethod(true)
|
||||
, _hasRemoveMonoMethod(true)
|
||||
{
|
||||
//_raiseMethod = New<MMethod>(parentClass, StringAnsi("raise_" + _name), handle, 1, attributes);
|
||||
_hasAddMonoMethod = addMethodHandle != nullptr;
|
||||
if (_hasAddMonoMethod)
|
||||
_addMethod = New<MMethod>(parentClass, StringAnsi("add_" + _name), addMethodHandle, 1, attributes);
|
||||
else
|
||||
_addMethod = nullptr;
|
||||
_hasRemoveMonoMethod = removeMethodHandle != nullptr;
|
||||
if (_hasRemoveMonoMethod)
|
||||
_removeMethod = New<MMethod>(parentClass, StringAnsi("remove_" + _name), removeMethodHandle, 1, attributes);
|
||||
else
|
||||
_removeMethod = nullptr;
|
||||
}
|
||||
|
||||
MMethod* MEvent::GetAddMethod() const
|
||||
{
|
||||
return nullptr; // TODO: implement MEvent in .NET
|
||||
return _addMethod;
|
||||
}
|
||||
|
||||
MMethod* MEvent::GetRemoveMethod() const
|
||||
{
|
||||
return nullptr; // TODO: implement MEvent in .NET
|
||||
return _removeMethod;
|
||||
}
|
||||
|
||||
bool MEvent::HasAttribute(MClass* monoClass) const
|
||||
|
||||
Reference in New Issue
Block a user