C# 利用反射调用类下的方法
- namespace TestReflection
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string MethodName = comboBoxEdit1.SelectedItem.ToString();
- TestMethod(MethodName, MethodName);
- }
-
-
-
-
-
-
- private void TestMethod(string MethodName, string Text)
- {
- try
- {
-
- Type type = Assembly.Load("TestReflection").GetType("TestReflection.Test");
-
-
- MethodInfo method = type.GetMethod(MethodName);
-
-
- object obj = Activator.CreateInstance(type);
-
-
- object[] parameters = new object[] { this, Text };
-
-
-
- method.Invoke(obj, parameters);
- }
- catch
- {
-
- }
- }
-
- }
- }
原文地址:https://www.cnblogs.com/tsql/p/8744263.html