- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
System.Reflection.Type 包含 GetInterfaceMap这有助于确定什么方法从接口(interface)实现某些方法。
Mono.Cecil 是否包含这样的内容?或者如何实现这种行为?
最佳答案
不,Cecil 不提供这样的方法,因为 Cecil 只按原样为我们提供 CIL 元数据。 (有项目Cecil.Rocks,里面有一些有用的扩展方法,但不是这个)
在 MSIL 中,方法有一个属性“overrides”,它包含对该方法覆盖的方法的引用(在 Cecil 中,MethodDefinition 类中确实有一个属性 Overrides)。但是,该属性仅在某些特殊情况下使用,例如显式接口(interface)实现。通常这个属性留空,哪些方法被有问题的方法覆盖是基于约定的。这些约定在 ECMA CIL 标准中进行了描述。简而言之,方法会覆盖具有相同名称和相同签名的方法。
以下代码片段可能对您以及本次讨论有所帮助:http://groups.google.com/group/mono-cecil/browse_thread/thread/b3c04f25c2b5bb4f/c9577543ae8bc40a
public static bool Overrides(this MethodDefinition method, MethodReference overridden)
{
Contract.Requires(method != null);
Contract.Requires(overridden != null);
bool explicitIfaceImplementation = method.Overrides.Any(overrides => overrides.IsEqual(overridden));
if (explicitIfaceImplementation)
{
return true;
}
if (IsImplicitInterfaceImplementation(method, overridden))
{
return true;
}
// new slot method cannot override any base classes' method by convention:
if (method.IsNewSlot)
{
return false;
}
// check base-type overrides using Cecil's helper method GetOriginalBaseMethod()
return method.GetOriginalBaseMethod().IsEqual(overridden);
}
/// <summary>
/// Implicit interface implementations are based only on method's name and signature equivalence.
/// </summary>
private static bool IsImplicitInterfaceImplementation(MethodDefinition method, MethodReference overridden)
{
// check that the 'overridden' method is iface method and the iface is implemented by method.DeclaringType
if (overridden.DeclaringType.SafeResolve().IsInterface == false ||
method.DeclaringType.Interfaces.None(i => i.IsEqual(overridden.DeclaringType)))
{
return false;
}
// check whether the type contains some other explicit implementation of the method
if (method.DeclaringType.Methods.SelectMany(m => m.Overrides).Any(m => m.IsEqual(overridden)))
{
// explicit implementation -> no implicit implementation possible
return false;
}
// now it is enough to just match the signatures and names:
return method.Name == overridden.Name && method.SignatureMatches(overridden);
}
static bool IsEqual(this MethodReference method1, MethodReference method2)
{
return method1.Name == method2.Name && method1.DeclaringType.IsEqual(method2.DeclaringType);
}
// IsEqual for TypeReference is similar...
关于c# - Mono.Cecil 类似于 Type.GetInterfaceMap 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4917509/
Mono 适合开发服务器应用程序,还是只适合开发桌面应用程序?我想用 C# 为 Linux 开发服务器应用程序。我想用 C#/XNA 编写一个第一人称射击 (FPS) 游戏,并且我有一个 Linux
今天我的 Ubuntu 将 Mono 更新到了 4.2.1.102。它不会允许我绝对需要运行的某个程序。如何将其降级到 4.0.5.1?我已经尝试过了... sudo apt-get install
我最近一直在使用 Java 中的 react 器库和 Spring 框架学习响应式(Reactive)编程,并且在很大程度上我已经能够掌握它。然而,我发现自己多次遇到同样的情况,并希望得到一些关于我哪
虽然 Mono 支持对我们来说不是什么大问题,但我认为 OpenRasta 支持它,因为它有一些关于它的提交消息.. 好吧,我尝试在 Mono 上构建它并获得了模棱两可的类型引用(在手动创建了 10
如何使用单声道嵌入调用创建通用 List 对象?我可以得到 List 的 MonoClass: MonoClass* list = mono_class_from_name(mscorlibimage
我正在考虑使用 Mono.Cairo 作为轻量级 CAD 系统的基础。 但不知道表现如何。 CAD 系统产生了很多 重绘并且可以在其中包含大量数据和大量文本。 如果不是开罗,那么欢迎任何其他建议。 我
我花了一周的时间尝试让我的 XSP 服务器处理简单的静态内容:html 页面、js 文件、gif、jpegs 等...没有 ASP.NET。当使用浏览器浏览此页面时,该服务器总是随机崩溃。我的环境是:
我想确定构建和安装当前 Mono 运行时的版本(如何在 Git 中正确调用它?)。 $ dmcs --version Mono C# compiler version 2.9.0.0 但这绝对不够。
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 10 年前关闭。 Improve this
我已经在 ubuntu 14.0 lts 中下载并安装了 vscode,并包含了现有的 node.js 项目。首先认为我必须使用 vscode 调试我的应用程序,为此我必须调试(ctrl+shift+
嗨,我刚刚开始学习响应式编程 我这里有这段代码,我的流程应该是我将调用 tokenRepository 来获取 token ,然后使用 token.getAccessToken() 用作 cardRe
几天来,我一直在尝试在 Centos 6.3 上运行的 XSP 2.10 软件包中获取 mono 3.0 和 nginx 1.2.4 和 fastcgi-mono-serverX ...XSP4 服务
我正在尝试使用 Mono 创建一个 Mac 包。当我执行时: mkbundle file.exe --deps -o FILE 我在编译过程中得到了这个: fatal error: "
Mono 2.0 was just officially released .您认为最重要的单一功能是什么? 最佳答案 Windows.Forms 绝对领先...这可能是我最兴奋的功能。 LINQ-t
我正在将我的应用程序更新到 ios6,但我遇到了以下问题 无法通过架构构建应用程序 支持 ARMv6 + ARM v7 但仅支持 ARM v7(错误是 iOS6 与 ARM v6 不兼容)。这意味着我
你好,我有 CentOS,我正在尽我最大的努力更新 Mono,我目前有 1.2.4 版,我试图通过 xbuild 编译一些东西,但我想它不起作用,因为我正在使用旧版本的单声道。 请在将任何指南链接到我
我正在尝试使用以下代码创建包含名称(作为标签)和关闭按钮(作为带有图像的按钮)的新 GTK Notebook 选项卡: Label headerLabel = new Label(); headerL
我正在为需要使用 AppleScript 的 OSX 编写一个单声道应用程序。我正在使用 AppleScript class from the Monodevelop source大多数情况下都可以正
我正在尝试构建一个控制台应用程序来测试 redis/mono 通信。我一直在使用 Monodevelop 4.0 (Xamarin Studios)+Nuget Port 在 mac os 上与 Se
为了摆脱软 float 与硬 float ABI 问题,我尝试在我的 Raspberry Pi 上安装最新版本的单声道 git clone https://github.com/mono/mono.g
我是一名优秀的程序员,十分优秀!