What's a global method?

What is a global method in .net? I'm talking about the ones created by the ModuleBuilder.DefineGlobalMethod method.

Can these methods be called from C# or other .net languages?


Hard to talk about this at all in familiar terms, this capability is not at all exposed in the C# or VB.NET languages. The C++/CLI compiler uses it however. The way it is shown in disassemblers like Ildasm.exe or Reflector is also not standardized.

Perhaps the best angle is Reflector, take a look-see at the System.Data.dll assembly. It is in an unnamed namespace ("-" in Reflector), <Module> node. The .cctor you see there is a module initiailizer. Same kind of animal as a static class constructor but at the module level. It runs when the assembly gets loaded. C++/CLI uses it to initialize the C runtime library.

The ___CxxCallUnwindDtor() method you find there is an example of a "global method". The C++/CLI language doesn't give any way to make these kind of functions public, they are always embedded in the metadata with internal accessibility. And can thus not be called directly from a C# or VB.NET program. I haven't played enough with ModuleBuilder to know if that can be messed with at all beyond what C++/CLI does. This is all very obscure and not actually that useful.


Global method means that the method can be called without fully qualifying it's name ie

Method(Param) instead of Module.Method(Param).

In vb a public method inside a module is global.

In c# a public static method in a static class is global.

链接地址: http://www.djcxy.com/p/3032.html

上一篇: Bada在Linux中的开发

下一篇: 什么是全球性的方法?