反射Reflection

                    Assembly assemly = Assembly.Load("Ruanmou.DB.SqlServer");//加载解决方案
                    Type testType = assemly.GetType("Ruanmou.DB.SqlServer.ReflectionTest");//加载解决方案中的类
                    object oTest = Activator.CreateInstance(testType);//使用与指定参数匹配程度最高的构造函数来创建指定类型的实例。
                    {
                        MethodInfo method = testType.GetMethod("Show1");//获取方法
                        method.Invoke(oTest, null);//同步执行
                    }
                    {
                        MethodInfo method = testType.GetMethod("Show2");//带参数
                        method.Invoke(oTest, new object[] { 1332 });
                    }

猜你喜欢

转载自blog.csdn.net/qq_38173650/article/details/83591879