你可以做什么的MSIL,你不能在C#或VB.NET呢?你可以、做什么、你不、能在

2023-09-02 21:55:14 作者:持刀与人争

所有code写的.NET语言编译成MSIL,但是否有具体任务/操作,你只能用做MSIL直接?

让我们也有事情在MSIL比C#,VB.NET,F#,J#或任何其他.NET语言做更容易。

到目前为止,我们有这样的:

尾递归 通用​​有限公司/逆变 重载仅在返回类型而不同 覆盖访问修饰符 在有不能从System.Object继承的类 过滤异常(可以在vb.net中完成) 调用当前静态类类型的虚方法。 获取一个值类型的盒装版的句柄。 请在try /故障。 不允许使用的名称的用法。 定义自己的参数构造函数的值类型的。 与定义事件募集元素。 部分由CLR而不是由C#允许的转换。 请非的main()法为 .entrypoint 。 与本地工作 INT 和本地无符号整型类型直接。 播放短暂指针 在MethodBodyItem emitbyte指令 手掷非System.Exception的类型 在继承枚举(未验证) 您可以把字节数组为int的(更小的4倍)阵列。 您可以有一个字段/方法/属性/事件都具有相同的名称(未验​​证)。 您可以跳转回从自身的catch块try块。 您可以访问famandassem访问符(受保护的内部是FAM 或 ASSEM) 直接进入<模块> 类定义全局函数,或模块初始化 解决方案

MSIL允许过载而区别仅是因为返回类型

 呼叫无效[mscorlib程序] System.Console ::写(串)
 

  callvirt INT32 ...
 
vb.net,这个是怎么回事

All code written in .NET languages compiles to MSIL, but are there specific tasks / operations that you can do only using MSIL directly?

Let us also have things done easier in MSIL than C#, VB.NET, F#, j# or any other .NET language.

So far we have this:

Tail recursion Generic Co/Contravariance Overloads which differ only in return types Override access modifiers Have a class which cannot inherit from System.Object Filtered exceptions (can be done in vb.net) Calling a virtual method of the current static class type. Get a handle on the boxed version of a value type. Do a try/fault. Usage of forbidden names. Define your own parameterless constructors for value types. Define events with a raise element. Some conversions allowed by the CLR but not by C#. Make a non main() method as the .entrypoint. work with the native int and native unsigned int types directly. Play with transient pointers emitbyte directive in MethodBodyItem Throw and catch non System.Exception types Inherit Enums (Unverified) You can treat an array of bytes as a (4x smaller) array of ints. You can have a field/method/property/event all have the same name(Unverified). You can branch back into a try block from its own catch block. You have access to the famandassem access specifier (protected internal is famorassem) Direct access to the <Module> class for defining global functions, or a module initializer.

解决方案

MSIL allows for overloads which differ only in return types because of

call void [mscorlib]System.Console::Write(string)

or

callvirt int32 ...