de-vraag
  • 質問
  • タグ
  • ユーザー
通知:
報酬:
登録
登録すると、質問に対する返答やコメントが通知されます。
ログイン
すでにアカウントをお持ちの方は、ログインして新しい通知を確認してください。
追加された質問、回答、コメントには報酬があります。
さらに
ソース
編集
Jonathan Shore
Jonathan Shore
質問

メソッドのシグネチャを評価するコンテキストでMonoTypeを使用する方法

C ++からCLRクラスのメソッドを呼び出せるようにしたい。特に、いくつかのクラスにはオーバーロードされたメソッドが含まれている可能性があるので、メソッド名とパラメータの署名の両方に基づいてクラスのメソッドを検索する必要があります。

私はこのような関数を持っています:

MonoMethod* find_method (
    MonoDomain* domain, 
    MonoClass* type, 
    const char* name, 
    int nargs,
    MonoClass** types)    

私はクラスのメンバーを繰り返し、名前で一致するメンバーを見つける。次に、メソッドのパラメーターをチェックして、それらがこの関数のtypesパラメーターで必要なリストと一致するかどうかを確認する必要があります。

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:

  1. access the MonoClass and MonoType struct fields
    • attempting to access fields in these structs results in error, as incomplete structs
  2. 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)
  3. 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

MonoType *またはMonoClass *のフィールドにアクセスするときと同じようにコンパイルしない2つの補助関数を次に示します。コンパイラは、2つの構造が不完全であることを示す文句を言います。

//
//  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;
}
0 2011-10-27T19:34:46+00:00 1
Jonathan Shore
Jonathan Shore
編集された質問 27日 10月 2011 в 9:36
プログラミング
mono
embedding
lupus
28日 10月 2011 в 7:32
2011-10-28T07:32:08+00:00
さらに
ソース
編集
#56792013

非公開のモノラルヘッダーは含めないでください。内部を変更するとアプリケーションが壊れます。

MonoType *から型enum値にアクセスするには、(metadata/metadata.hから)mono_type_get_type()関数を呼び出す必要があります。 MONO_TYPE_CLASSとMONO_TYPE_VALUETYPEについては、mono_type_get_class()でMonoClass *値にアクセスできます。

MonoClass *を使用して引数の型を表すことは、たとえば参照渡しの引数を表すことができないため、基本的には間違っていることに注意してください。

代入可能で一致させる必要がある場合は、mono_class_is_assignable_from()を使用できますが、byref引数を処理し、enum型がその基礎となる整数型に自動変換できるようにするかどうかを決定する必要があることに注意してください。

基本的な型クラスは以下のような関数で簡単に取り出すことができます: mono_get_int32_class()、mono_get_boolean_class()など

2
0
質問の追加
カテゴリ
すべて
技術情報
文化・レクリエーション
生活・芸術
科学
プロフェッショナル
事業内容
ユーザー
すべて
新しい
人気
1
Roxana Elizabeth CASTILLO Avalos
登録済み 15時間前
2
Hideo Nakagawa
登録済み 1日前
3
Sergiy Tytarenko
登録済み 3日前
4
shoxrux azadov
登録済み 5日前
5
Koreets Koreytsev
登録済み 1週間前
© de-vraag :年
ソース
stackoverflow.com
ライセンス cc by-sa 3.0 帰属