23.2 Examining Module Information

 <  Day Day Up  >  

You want to enumerate each module within an assembly and inspect their properties.


Technique

The GetModules method of an Assembly object returns an array of Module objects that you can use to view the properties of each module defined in an assembly. The Module class contains fewer properties and methods than the Assembly class simply because it's a container of types with no need for identity information such as an assembly. In the following code, which continues from the previous recipe, each module within an assembly is enumerated and placed in a node underneath the assembly name within the TreeView :

 
 private void PopulateTree() {     TreeNode newNode = new TreeNode( mAssembly.GetName().Name );     newNode.Tag = mAssembly;     tvAssembly.Nodes.Add( newNode );     foreach( Module mod in mAssembly.GetModules() )     {         AddModule( mod, newNode );     } } private void AddModule( Module mod, TreeNode parent ) {     TreeNode newNode = new TreeNode( mod.Name );     newNode.Tag = mod;     parent.Nodes.Add( newNode ); } 

Comments

The Module class represents the second tier within the assembly hierarchy. Without first going through an assembly, you can't get to a module. Modules themselves are generally just accessed via the CLR when navigating through the hierarchy because most information is contained within the types that it contains. In other words, you work with assemblies and you work with data types, but rarely do you have to work at the module level. Additionally, if you decide to implement a multifile assembly in which code written in one .NET programming language is placed within the same assembly as code written in a different .NET language, then you have to work on the module level (at least during build time).

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net