using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
private static string Display()
{
return "sex";
}
private string Spec()
{
return "detail";
}
public static void Main(string[] args)
{
//通过反射来执行类的静态方法
Type tx = typeof(ConsoleApplication1.Program);
MethodInfo mf = tx.GetMethod("Display", BindingFlags.NonPublic|BindingFlags.Static, null, new Type[] { }, null);
string saf = (string)mf.Invoke(null,null);
Console.WriteLine(saf);
Console.ReadKey();
//通过反射来执行类的实例方法
//string[] str = new string[2];
Program p1 = new Program();
Type t = p1.GetType();
//因为此句我分析好久
MethodInfo mi = t.GetMethod("Spec", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);
//通过反射执行ReturnAutoID方法,返回AutoID值
string strx = mi.Invoke(p1, null).ToString();
Console.WriteLine(strx);
Console.ReadKey();
}
}
}