using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Reflection;
namespace WindowsFormsApplication4
{
public class MyClass
{
public int AddNumb(int numb1, int numb2)
{
int result = numb1 + numb2;
return result;
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
// Type type1 = Type.GetType("MyClass");
Type type1 = Type.GetType("WindowsFormsApplication4.MyClass");
// Type type1 = typeof(MyClass);
// typeof()
object obj = Activator.CreateInstance(type1);
// object obj = Activator.CreateInstance()
object[] mParam = new object[] { 5, 10 };
//invoke AddMethod, passing in two parameters
int res = (int)type1.InvokeMember("AddNumb", BindingFlags.InvokeMethod,
null, obj, mParam);
Console.Write("Result: {0} /n", res);
Console.WriteLine(obj.ToString());
//Console.WriteLine("/nReflection.MethodInfo");
//// Create MyClass object
//MyClass myClassObj = new MyClass();
//// Get the Type information.
//Type myTypeObj = myClassObj.GetType();
//// Get Method Information.
//MethodInfo myMethodInfo = myTypeObj.GetMethod("AddNumb");
//object[] mParam = new object[] { 5, 10 };
//// Get and display the Invoke method.
//Console.Write("/nFirst method - " + myTypeObj.FullName + " returns " +
// myMethodInfo.Invoke(obj, mParam) + "/n");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
System.ComponentModel.BindingList<myClass> bindingList = new System.ComponentModel.BindingList<myClass>(originalList);