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

📄 ch6_2.cs

📁 《c#技术内幕代码》
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -