Reflection - assembly in .net

c#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ReflectionCS
{
    
class Program
    {
        
static void Main(string[] args)
        {
            String path 
= @"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll";
            Assembly assembly 
= Assembly.LoadFile(path);
            ShowAssemblyInfo(assembly);
            Assembly currentAssembly 
= Assembly.GetExecutingAssembly();
            ShowAssemblyInfo(currentAssembly);
            Console.ReadLine();
        }

        
static void ShowAssemblyInfo(Assembly assembly)
        {
            Console.WriteLine(assembly.FullName);
            Console.WriteLine(
"From GlobalAssemblyCache? {0}", assembly.GlobalAssemblyCache);
            Console.WriteLine(
"Path: {0}", assembly.Location);
            Console.WriteLine(
"Version: {0}", assembly.ImageRuntimeVersion);
            
foreach (Module module in assembly.GetModules())
            {
                Console.WriteLine(
"Module: {0}", module.Name);
            }
            Console.WriteLine();
        }
    }
}

 


vb.net:

Imports System.Reflection
Module Module1

    
Sub Main()
        
Dim path As String = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll"
        
Dim assembly As Assembly = assembly.LoadFile(path)
        ShowAssemblyInfo(
assembly)
        
Dim currentAssembly As Assembly = assembly.GetExecutingAssembly()
        ShowAssemblyInfo(currentAssembly)
        Console.ReadLine()
    
End Sub

    
Sub ShowAssemblyInfo(ByVal assembly As Assembly)
        Console.WriteLine(
assembly.FullName)
        Console.WriteLine(
"From GlobalAssemblyCache? {0}"assembly.GlobalAssemblyCache)
        Console.WriteLine(
"Path: {0}"assembly.Location)
        Console.WriteLine(
"Version: {0}"assembly.ImageRuntimeVersion)
        
For Each [ModuleAs [ModuleIn assembly.GetModules
            Console.WriteLine(
"Module: {0}", [Module].Name)
        
Next
        Console.WriteLine()
    
End Sub

End Module

 

posted @ 2009-05-04 09:57  N/A2011  阅读(227)  评论(0编辑  收藏  举报