Ik wil methoden op CLR-klassen kunnen aanroepen vanuit C ++. In het bijzonder kunnen sommige klassen overbelaste methoden bevatten, dus ik moet de methoden van een klasse doorzoeken op basis van zowel de methode-naam als de parametersignatuur.
Ik heb een functie als deze:
MonoMethod* find_method (
MonoDomain* domain,
MonoClass* type,
const char* name,
int nargs,
MonoClass** types)
Ik herhaal de leden van de klas en vind een overeenkomend lid bij naam. Ik moet dan de parameters van de methode controleren en zien of ze overeenkomen met de lijst die is vereist in de parameter types van deze functie.
mono_signature_get_params()
is then used to iterate over the parameters for each method with a matching name.
Questions:
How can I do the following:
- access the MonoClass and MonoType struct fields
- attempting to access fields in these structs results in error, as incomplete structs
- compare a list of method parameters with another list provided as input to the function
- cannot compare by enum as cannot access the enum field (see above)
- get
MonoClass*
constants for fundamental types int32_class, int64_class
, etc.
- want to be able to easily compose a signature array using primitive type class constants
Hier zijn 2 hulpfuncties die niet worden gecompileerd omdat bij het benaderen van velden in MonoType * of MonoClass * de compiler klaagt dat de twee structuren onvolledig zijn:
//
// Detetermine whether classes A and B are equivalent
//
static bool IsEquivalent (MonoType* typeA, MonoType* typeB)
{
MonoTypeEnum Ta = typeA->type;
MonoTypeEnum Tb = typeB->type;
//if basic type not a match, can punt
if (Ta != Tb)
return false;
//if simple type, nothing further to check
if (Ta < MONO_TYPE_PTR)
return true;
//check class
if (Ta == MONO_TYPE_CLASS)
return typeA->data.klass = typeB->data.klass;
else
return typeA->data.klass = typeB->data.klass;
}
//
// Determine whether parameters in signature match incoming parameters
//
static bool types_match (
MonoMethodSignature* sig,
MonoClass** types,
int nargs)
{
void* iter = NULL;
MonoType* type = NULL;
int i = 0;
while (type = mono_signature_get_params (sig, &iter))
{
if (!IsEquivalent (type, types[i++]->this_arg))
return false;
}
return true;
}