1

私はMono.CecilでIL織りを少しやっていますが、この問題に遭遇しています:

Member 'System.Collections.Generic.List`1/Enumerator' is declared in
another module and needs to be imported

リスト列挙子を持つモジュールをどのようにインポートしますか?

次のように、列挙子を取得するために使用しているTypeReference(System.Collections.Generic.List`1< blah >) があります。

var instanceType = (typeReference as GenericInstanceType);
var list = instanceType.Resolve();

MethodDefinition getEnumerator;
if (!list.TryGetMethod("GetEnumerator", out getEnumerator))
    throw ...

...TryGetMethodは、問題の型でその名前のメソッドを検索するカスタム拡張です。

次に、コードのさらに下で getEnumerator を次のように使用します。

instructions.Add(Instruction.Create(OpCodes.Callvirt, getEnumerator));

私は何を間違っていますか?

4

1 に答える 1

1

私はそれを考え出した。リストの列挙子を取得するには、次のようMethodReferenceにメソッドの を取得する必要があります。GetEnumerator

Type listType = typeof (List<>);

MethodReference getEnumerator = moduleDefinition
    .Import(listType.GetMethod("GetEnumerator"));
于 2013-04-10T05:59:33.350 に答える