日期:2014-05-18 浏览次数:20983 次
public class Class1 { public Class1( ) { } public string Method1( ) { return " word"; } public string Method2( string strName ) { return strName; } } public class Class2 { public Class2( ) { } public bool FindMethod( string className , string methodName , Type[ ] paramType) { Type type = Type.GetType( className , true , true ); object dObj = Activator.CreateInstance( type ); MethodInfo method; if( paramType!= null ) method = type.GetMethod( methodName , paramType); else method = type.GetMethod( methodName , new Type[0] ); return method != null; } } //调用: Response.Write( new Class2( ).FindMethod( "Class1" , "Method1" , null ); Response.Write( new Class2( ).FindMethod( "Class1" , "Method2" , new Type[ ] { typeof( string ) } ) );
------解决方案--------------------
写了代码,但是没发现Form_Load呢!
其他的方法基本上都得到了;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Type t = typeof(Form1); MethodInfo[] info = t.GetMethods(); foreach (MethodInfo i in info) { if (i.Name.ToLower().IndexOf("load") > -1) { MessageBox.Show(i.Name); } } } } }