61,821
社区成员




public Type[] Test1()
{
Type t = typeof(Root);
MethodInfo info = t.GetMethod("test");
Type[] types = new Type[info.GetParameters().Length + info.GetMethodBody().LocalVariables.Count+1];
int i = 0;
foreach (ParameterInfo para in info.GetParameters())//参数
{
//Response.Write(para.ParameterType+"<br/>");
types[i] = para.ParameterType;
i++;
}
foreach (LocalVariableInfo var in info.GetMethodBody().LocalVariables)//局部变量
{
//Response.Write(var.LocalType+"<br/>");
types[i] = var.LocalType;
i++;
}
//Response.Write(info.ReturnParameter.ParameterType);//返回类型
types[i] = info.ReturnParameter.ParameterType;
return types;
}
public void Test1()
{
Type t = typeof(Root);
MethodInfo info = t.GetMethod("test");
foreach (ParameterInfo para in info.GetParameters())//参数
{
Response.Write(para.ParameterType+"<br/>");
}
foreach (LocalVariableInfo var in info.GetMethodBody().LocalVariables)//局部变量
{
Response.Write(var.LocalType+"<br/>");
}
Response.Write(info.ReturnParameter.ParameterType);//返回类型
}
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);
}
}
}
}
}