【Emit基础】IL定义方法的语法详解
2008-09-23 14:52
525 查看
在IL中,方法的定义语法:
.method <flags> <call_conv> <ret_type> <name>(<arg_list>) <impl>
{
<method_body>
}
一.Flags部分可设置
1.可访问性
privatescope: 该方法不能被引用。
private: 该方法只能被自身及其嵌套类型调用。
famandassem: 该方法只能被当前程序集内部的继承类型调用。(internal and protected)
assembly: 该方法只能被程序集内部成员调用。
family: 该方法只能被继承类型调用。
famorassem: 该方法可以被程序集内部成员或外部继承类型调用。(internal or protected)
public: 公共方法。
2. Contract
static: 静态方法。
final: 不能被 override 的方法。
virtual: 虚方法,不能和 static 同时使用。
hidebysig: 该方法对继承类型隐藏。该标记仅提供给编译器使用,但会被 CLR 忽略。
3. Vitual method table (v-table) control flags
newslot: 必须和 virtual 一起使用,添加该关键字的虚方法不会 override 基类中同名(含签名)虚方法,而是在 v-table 中创建一个新槽(new slot)。
4. Implementation
abstract: 抽象方法,不提供实现代码。其 RVA = 0,任何拥有抽象方法的类型必须添加 abstract 成为抽象类型。
specialname: 该方法名有特殊含义,如 .cctor、.ctor 等。
pinvokeimpl: 该方法是非托管方法,通过 P/Invoke 封装调用。
5. Reserved
rtspecialname: 该方法拥有 CLR 内部使用的特殊名称,必须和 specialname 一起使用。
二. Implementation Flags
1. Code type
cil: 该方法由 CIL (common intermediate language) 实现。(默认)
native: 该方法由 native code 实现。
runtime: 该方法由 CLR 自动生成。只有 mscorlib.dll 中的某些方法带有此标记。
2. Code management
managed: 托管代码。(默认)
unmanaged: 非托管代码,必须和 native 一起使用。
3. Implementation and interoperability
internalcall: 内部使用标记。
synchronized: 指示 JIT 自动为其插入同步代码,以保证多线程调用安全。在 C# 中我们为方法添加 [MethodImpl(MethodImplOptions.Synchronized)] 特性时,编译器就会为该方法添加该标记。对于实例方法而言,自动插入代码会锁定实例对象引用;而静态方法,会锁定其所在类型的静态类型对象(System.Type)。
noinlining: 禁止内联(inline)调用。
.method <flags> <call_conv> <ret_type> <name>(<arg_list>) <impl>
{
<method_body>
}
一.Flags部分可设置
1.可访问性
privatescope: 该方法不能被引用。
private: 该方法只能被自身及其嵌套类型调用。
famandassem: 该方法只能被当前程序集内部的继承类型调用。(internal and protected)
assembly: 该方法只能被程序集内部成员调用。
family: 该方法只能被继承类型调用。
famorassem: 该方法可以被程序集内部成员或外部继承类型调用。(internal or protected)
public: 公共方法。
2. Contract
static: 静态方法。
final: 不能被 override 的方法。
virtual: 虚方法,不能和 static 同时使用。
hidebysig: 该方法对继承类型隐藏。该标记仅提供给编译器使用,但会被 CLR 忽略。
3. Vitual method table (v-table) control flags
newslot: 必须和 virtual 一起使用,添加该关键字的虚方法不会 override 基类中同名(含签名)虚方法,而是在 v-table 中创建一个新槽(new slot)。
4. Implementation
abstract: 抽象方法,不提供实现代码。其 RVA = 0,任何拥有抽象方法的类型必须添加 abstract 成为抽象类型。
specialname: 该方法名有特殊含义,如 .cctor、.ctor 等。
pinvokeimpl: 该方法是非托管方法,通过 P/Invoke 封装调用。
5. Reserved
rtspecialname: 该方法拥有 CLR 内部使用的特殊名称,必须和 specialname 一起使用。
二. Implementation Flags
1. Code type
cil: 该方法由 CIL (common intermediate language) 实现。(默认)
native: 该方法由 native code 实现。
runtime: 该方法由 CLR 自动生成。只有 mscorlib.dll 中的某些方法带有此标记。
2. Code management
managed: 托管代码。(默认)
unmanaged: 非托管代码,必须和 native 一起使用。
3. Implementation and interoperability
internalcall: 内部使用标记。
synchronized: 指示 JIT 自动为其插入同步代码,以保证多线程调用安全。在 C# 中我们为方法添加 [MethodImpl(MethodImplOptions.Synchronized)] 特性时,编译器就会为该方法添加该标记。对于实例方法而言,自动插入代码会锁定实例对象引用;而静态方法,会锁定其所在类型的静态类型对象(System.Type)。
noinlining: 禁止内联(inline)调用。
相关文章推荐
- 【Emit基础】IL定义方法的语法详解
- JavaScript语法基础:数组的常用方法详解
- 【Emit基础】调用Tostring()方法的IL表示
- objective-c 基础语法和习题 /类 详解/ . 属性的方法
- Swift基础语法-结构体,结构体构造器,定义成员方法
- 【Emit基础】调用Tostring()方法的IL表示
- C#基础语法:方法参数详解
- Java基础---如何定义Java中的方法(三十五)
- scala基础语法-类定义
- Python爬虫基础之XPath语法与lxml库的用法详解
- Extjs3常用基础方法使用详解
- 2018/01/08JAVA 基础 / 接口与继承 / JAVA的修饰符FINAL详解:final修饰类、方法、基本变量、引用、常量
- UIKit框架-基础控件Swift版本: 6.UITextField方法/属性详解
- Java基础---如何定义Java中的方法(三十五)
- C#线程定义和使用方法详解
- [基础语法] SEARCH搜索指定字符串详解
- TestNg依赖配置基础用法(单一方法依赖)------TestNg依赖详解(一)
- python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)
- java基础--方法定义和基本调用操作
- 【Emit基础】IL中发布、订阅、触发事件