System.Reflection Namespace
Contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata. These types also can be used to manipulate instances of loaded types, for example, to hook up events or to invoke methods. To dynamically create types, use the System.Reflection.Emit namespace., see the official webpage.
Assembly class use assembly type provides various properties and methods for getting any kind of information about assembly, getting loaded assemblies, and loading assemblies.
See this list of some useful properties and description:

  • Codebase – returns the location of the assembly;
  • EntryPoint – returns the method information of the entry methods (Main method). Console applications return a reference to the Main method and dynamic link libraries (DLL) return NULL;
  • FullName – returns the full name of the assembly including version number, Culture, and PublicKeyToken;
  • GlobalAssemblyCache – this is bool property returns true if assembly loaded from GAC else returns false;
  • CustomAttributes – returns all the custom attributes of the assembly;
  • DefinedTypes – returns all the types in the assembly;
  • Modules – return all the modules in the assembly;
  • Codebase – returns the location of the assembly;
  • EntryPoint – returns the method information of the entry methods – Main method. The console applications return reference to the Main method and dynamic link libraries (DLL) returns NULL;
  • FullName – returns the full name of the assembly including version number, Culture, and PublicKeyToken;
  • GlobalAssemblyCache – bool property returns true if assembly loaded from GAC else returns false;
  • CustomAttributes – returns all the custom attributes of the assembly;
  • DefinedTypes – returns all the types in the assembly;
  • Modules – return all the modules in the assembly.

There are two types of assemblies:

  • Executable files (EXE)
  • Libraries (DLL)

This is a simple example:

This is the source code in C# :

You can use this form of usage with var:

  • var – requires less typing, is shorter, and easier to read;
  • var – requires code changes if the return type of a method call changes and to change the method declaration, not every place it’s used;
  • var – encourages you to use a descriptive name for the variable.

The assembly returns a type in an Assembly.
Here is another example with this feature:
GetCustomAttributesData – returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.

This is the source code in C#:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translate »