ch6_2.cs

来自「《c#技术内幕代码》」· CS 代码 · 共 59 行

CS
59
字号
using System;
using System.Reflection;

class CH6_2
{
    public static void Main( string[] args)
    {
       if ( args.Length > 0 )
          ShowClasses( args[0] );
    }
    public static void ShowMethods( Type t )
    {
       MethodInfo[] methods = t.GetMethods();
       foreach( MethodInfo m in methods )
       {
          Console.WriteLine("\nMethod Name: {0}", m.Name );
	  Console.WriteLine("Return Type: {0}", m.ReturnType );
	  // List parameters
	  
	  ParameterInfo[] ps = m.GetParameters();
	  foreach ( ParameterInfo p in ps )
	  {
	     Console.WriteLine("Parameter {0}", p.Name );
	     Console.WriteLine("Type: {0}", p.ParameterType );
	  }
       }
    }
    public static void ShowProperties( Type t )
    {
       PropertyInfo[] props = t.GetProperties();
       foreach( PropertyInfo p in props )
       {
          Console.WriteLine("\nProperty Name: {0}", p.Name );
          Console.WriteLine("Type: {0}", p.MemberType );
       }
    }
    
    public static void ShowClasses( string name )
    {
       Assembly assembly = Assembly.LoadFrom( name );
       if ( assembly != null )
       {
          // Get the classes from the assembly.
          Type[] typeArray = assembly.GetTypes ();

          Console.WriteLine ("Assembly Name: {0}", name);
          foreach (Type type in typeArray) 
          {
	      if ( type.IsClass )
	      {
	         Console.WriteLine("Class: {0}", type.FullName );
	         ShowMethods( type );
		 ShowProperties( type );
              }
          }
       }
    }
}

⌨️ 快捷键说明

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