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

📄 ch6_4.cs

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

class CH6_4
{
   public static void Main(string[] args)
   {
      // If they gave us at least two arguments,
      // check the assembly (arg 1) for a class
      // that contains a method (arg 2)
      if ( args.Length >= 2 )
         SearchForMethod( args[0], args[1] );
   }
   public static void SearchForMethod( 
       string AssemblyName,
       string MethodName )
   {
      // Step 1: Open the assembly
      Assembly assembly = Assembly.LoadFrom( 
                AssemblyName );
      if ( assembly == null )
      {
         Console.WriteLine("Unable to open {0}",
	    AssemblyName );
	 return;
      }
      
      // Step 2: Loop through all classes in 
      //         the assembly
      
      foreach ( Type t in assembly.GetTypes() )
      {
         // Is this a class?
	 if ( t.IsClass == false )
	    continue; // No. Skip it
	 
         // Get all of the methods in the class
	 foreach ( MethodInfo m in t.GetMethods() )
	 {
	    if ( m.Name == MethodName )
	    {
	       Console.WriteLine("Class {0} contains method",
	          t.FullName );
	    }
	 }
      }
   }
}

⌨️ 快捷键说明

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