⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch6_6.cs

📁 《c#技术内幕代码》
💻 CS
字号:
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections;

class CH6_6
{
   public static void DumpParameters( ParameterInfo[] pars )
   {
      // Dump them out
      foreach ( ParameterInfo pi in pars )
      {
         Console.WriteLine("\n   Parameter Name: {0}", 
	    pi.Name );
	 Console.WriteLine("   Parameter Type: {0}", 
	    pi.ParameterType );
	 Console.WriteLine("   Is In? {0}", 
	    pi.IsIn );
	 Console.WriteLine("   Is Out? {0}",
	    pi.IsOut );
      }
   }
   
   public static void DumpType ( Type t )
   {
      // Dump the constructors
      ConstructorInfo[] cons = t.GetConstructors();
      foreach (ConstructorInfo ci in cons )
      {
         // Get all the parameters
         ParameterInfo[] pars = ci.GetParameters();
         Console.WriteLine("\nConstructor: {0}", ci.Name);
         DumpParameters( pars );
      }
      
      // Dump each method
      MethodInfo[] methods = t.GetMethods();
      foreach ( MethodInfo m in methods )
      {
         Console.WriteLine("\nMethod: {0}", m.Name );
	 Console.WriteLine("Return Type: {0}", m.ReturnType );
         // Get all the parameters
         ParameterInfo[] pars = m.GetParameters();
	 // Dump the parameters
	 DumpParameters( pars );
      }
   }
   public static void ShowType( string assemblyName,
                                string className )
   {
      Assembly assembly = Assembly.LoadFrom( assemblyName );
      if ( assembly == null )
         return;
	 
      Type[] types = assembly.GetTypes();
      foreach ( Type t in types )
      {
         // Only classes
         if ( t.IsClass == false )
	    continue;
	 // Only the one we want
	 string Name = (string)t.FullName;
	 if ( Name != className )
	    continue;
	 // Okay, this is it, dump it
	 DumpType( t );
      }
   }
   
   public static void Main(string[] args)
   {
      if ( args.Length >= 2 )
         ShowType( args[0], args[1] );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -