Кеширование всех событий, полей, свойств и методов класса включая родительские

This commit is contained in:
Kernell 2015-11-30 06:25:07 +03:00
parent 488bb0ed4c
commit a79c28940a
2 changed files with 100 additions and 15 deletions

View File

@ -16,12 +16,74 @@ CMonoClass::CMonoClass( MonoClass* pMonoClass, CMonoDomain* pDomain )
{
this->m_pClass = pMonoClass;
this->m_pDomain = pDomain;
MonoClass *pMonoBaseClass = pMonoClass;
while( pMonoBaseClass )
{
gpointer iter = nullptr;
while( MonoMethod* pMonoMethod = mono_class_get_methods( pMonoBaseClass, &iter ) )
{
const char* szName = mono_method_get_name( pMonoMethod );
this->m_Methods[ szName ].push_back( pMonoMethod );
}
iter = nullptr;
while( MonoProperty* pMonoProperty = mono_class_get_properties( pMonoBaseClass, &iter ) )
{
const char* szName = mono_property_get_name( pMonoProperty );
this->m_Properties[ szName ].push_back( pMonoProperty );
}
iter = nullptr;
while( MonoEvent* pMonoEvent = mono_class_get_events( pMonoBaseClass, &iter ) )
{
const char* szName = mono_event_get_name( pMonoEvent );
this->m_Events[ szName ] = pMonoEvent;
}
iter = nullptr;
while( MonoClassField* pMonoField = mono_class_get_fields( pMonoBaseClass, &iter ) )
{
const char* szName = mono_field_get_name( pMonoField );
this->m_Fields[ szName ] = pMonoField;
}
pMonoBaseClass = mono_class_get_parent( pMonoBaseClass );
}
}
CMonoClass::~CMonoClass( void )
{
this->m_pDomain->ReleaseClass( this );
this->m_pDomain = nullptr;
this->m_pClass = nullptr;
this->m_Fields.clear();
this->m_Events.clear();
for( auto iter : this->m_Properties )
{
iter.second.clear();
}
this->m_Properties.clear();
for( auto iter : this->m_Methods )
{
iter.second.clear();
}
this->m_Methods.clear();
}
MonoObject* CMonoClass::New( void )
@ -111,3 +173,13 @@ MonoMethod* CMonoClass::GetMethod( const char* szMethodName )
return nullptr;
}
MonoEvent* CMonoClass::GetEvent( const char* szEventName )
{
return this->m_Events.count( szEventName ) > 0 ? this->m_Events[ szEventName ] : nullptr;
}
MonoClassField* CMonoClass::GetField( const char* szFieldName )
{
return this->m_Fields.count( szFieldName ) > 0 ? this->m_Fields[ szFieldName ] : nullptr;
}

View File

@ -17,6 +17,11 @@ class CMonoClass;
#include "CMonoDomain.h"
typedef map< const char*, list< MonoMethod* > > MonoMethodMap;
typedef map< const char*, list< MonoProperty* > > MonoPropertyMap;
typedef map< const char*, MonoEvent* > MonoEventMap;
typedef map< const char*, MonoClassField* > MonoClassFieldMap;
class CMonoClass
{
private:
@ -24,6 +29,11 @@ private:
CMonoDomain* m_pDomain;
MonoEventMap m_Events;
MonoMethodMap m_Methods;
MonoPropertyMap m_Properties;
MonoClassFieldMap m_Fields;
public:
CMonoClass ( MonoClass* pMonoClass, CMonoDomain* pDomain );
~CMonoClass ( void );
@ -40,6 +50,9 @@ public:
MonoMethod* GetMethod ( const char* szMethodName, int iParamCount );
MonoMethod* GetMethod ( const char* szMethodName );
MonoEvent* GetEvent ( const char* szEventName );
MonoClassField* GetField ( const char* szFieldName );
MonoClass* GetMonoPtr ( void ) { return this->m_pClass; }
CMonoDomain* GetDomain ( void ) { return this->m_pDomain; }
};