Pages

2012-03-23

DOTNET: Create and Use a Code Module


So you need to do one or more of the following:
  • Improve your application’s performance and memory efficiency by ensuring that  the runtime loads rarely used types only when they are required
  • Compile types written in C# to a form you can build into assemblies being developed in other .NET languages
  • Use types developed in another language and build them into your C# assemblies



OK, build your C# source code into a module by using the command-line compiler and specifying the
/target:module compiler switch. To incorporate an existing module into your assembly, use the
/addmodule compiler switch.



Modules are the building blocks of .NET assemblies. Modules consist of a single file that contains the
following:
  • Microsoft Intermediate Language (MSIL) code created from your source code during compilation

  • Metadata describing the types contained in the module
  • Resources, such as icons and string tables, used by the types in the module



However, the C# compiler can’t compile your Microsoft Visual Basic .NET or
COBOL .NET code for inclusion in your assembly. To use code written in another
language, you can compile it into a separate assembly and reference it. But if you
want it to be an integral part of your assembly, then you must build it into a
module. Similarly, if you want to allow others to include your code as an integral
part of their assemblies, you must compile your code as modules. When you use
modules, because the code becomes part of the same assembly, members marked
as internal or protected internal are accessible, whereas they would not be if the
code had been accessed from an external assembly.

No comments:

Post a Comment