Inheritance Mono.Cecil:调用基类&x27;来自其他程序集的方法

Inheritance Mono.Cecil:调用基类&x27;来自其他程序集的方法,inheritance,assemblies,cil,il,mono.cecil,Inheritance,Assemblies,Cil,Il,Mono.cecil,如何通过名称获取对基类方法的MethodReference 我试过了 type.BaseType.Resolve().Methods; 如果我将包含基类的dll添加到assemblyresolver,它将返回方法。 但是如果我用 MSILWorker.Create(OpCodes.Call, baseMethod); (其中baseMethod是通过从已解析的TypeDefinition中搜索方法找到的) 由此产生的IL无法读取,甚至反射器冻结并退出 现在一些IL: 如果对类型调用私有方法:

如何通过名称获取对基类方法的MethodReference

我试过了

type.BaseType.Resolve().Methods;
如果我将包含基类的dll添加到assemblyresolver,它将返回方法。 但是如果我用

MSILWorker.Create(OpCodes.Call, baseMethod);
(其中baseMethod是通过从已解析的TypeDefinition中搜索方法找到的) 由此产生的IL无法读取,甚至反射器冻结并退出

现在一些IL:
如果对类型调用私有方法:

 call instance void SomeNamespace.MyClass::RaisePropertyChanged(string)
如果在基类型上调用受保护的方法:

call instance void [OtherAssembly]BaseNamespace.BaseClass::RaisePropertyChanged(string)

那么,我如何使用Mono.Cecil生成后者呢?

正如您所猜测的,您需要为模块获得适当的MethodReference范围。因此,如果你有:

TypeDefinition type = ...;
TypeDefintion baseType = type.BaseType.Resolve ();
MethodDefinition baseMethod = baseType.Methods.First (m => ...);
然后,baseType和baseMethod是来自另一个模块的定义。在使用baseMethod之前,需要导入对它的引用:

MethodReference baseMethodReference = type.Module.Import (baseMethod);
il.Emit (OpCodes.Call, baseMethodReference);

你能帮我解决类似的问题吗?谢谢。@TDaver:你应该使用mono-cecil谷歌群,而不是这样,你会有更好的机会快速得到答案。