偶就是想动态我那个dll里滴方法
那个dll里的命名空间是ModuleFun;
里面有两个类,一个是Module 对象 一个是 ModuleContent 类,我要调用的方法都在这个类里,用Module初始化他
ModuleFun.Module module = new ModuleFun.Module();
ModuleContent content = new ModuleContent(module);
Type type = content.GetType();
object o = Activator.CreateInstance(type,module);
MethodInfo mi = type.GetMethod("DayTeam");//这里是调用没有参数的的DayTeam方法
string result = (string)mi.Invoke(o, null);
Response.Write(result);
上面代码报错。。晕死咯还有个问题
如果DayTeam这个方法带参数咋办捏?
那个dll里的命名空间是ModuleFun;
里面有两个类,一个是Module 对象 一个是 ModuleContent 类,我要调用的方法都在这个类里,用Module初始化他
ModuleFun.Module module = new ModuleFun.Module();
ModuleContent content = new ModuleContent(module);
Type type = content.GetType();
object o = Activator.CreateInstance(type,module);
MethodInfo mi = type.GetMethod("DayTeam");//这里是调用没有参数的的DayTeam方法
string result = (string)mi.Invoke(o, null);
Response.Write(result);
上面代码报错。。晕死咯还有个问题
如果DayTeam这个方法带参数咋办捏?
解决方案 »
- 如何获取或设置DetailView里控件的值
- 求一个替换的实例项目,最好是WINFROM
- asp 制作图片查询功能
- 怎样获得DataGrid中的CheckBox的选中情况?
- 300分了!斑竹呢?孟子老大呢?进来看看吧!在发一次!webform中datagrid动态添加多个模板列和checkbox列问题!(两天了都没解决)
- 让人发疯的问题,请求大家帮忙!关于System.Data.SqlClient.SqlException
- 请问海波.net,水晶报表问题
- 紧急求助!!
- 求助,关于在web.config中的数据库设置
- 在Global.asax连接数据库(书上的源码)执行时总是出现这个错误(在连接选项值中发现无效分隔符 =。)
- 菜鸟用Objectdatasource,更新数据遇到问题 高手赐教
- 关于VSS的问题
Assembly ass = Assembly.LoadFrom(@"F:\txt\Solution1\psp\bin\Debug\psp.dll");
Type type = ass.GetTypes()[0];
MethodInfo mi = type.GetMethod("Showtxt");
object obj = ass.CreateInstance(type.ToString());
object[] o = new object[] { "b2b" };
string mystr =(string)mi.Invoke(obj,o);
Response.Write(mystr);
object o = Activator.CreateInstance(type, new object[] {module}); 2.方法参数传入
object[] o = new object[] { "b2b" };
string mystr =(string)mi.Invoke(obj,o);
Assembly ass = Assembly.LoadFrom(Server.MapPath("Bin") + "//" + "ModileFun.dll");
Type type = ass.GetTypes()[0];
MethodInfo mi = type.GetMethod("Test");
object obj = ass.CreateInstance(type.ToString());
object[] o = new object[] {module};
string mystr = (string)mi.Invoke(obj,o);
Response.Write(mystr);
改成这样提示:未找到类型“ModuleFun.ModuleContent”上的构造函数。
ModuleContent content = new ModuleContent(module);
Type type = content.GetType();
object o = Activator.CreateInstance(type, new object[] { module });
MethodInfo mi = type.GetMethod("Test");//这里是调用没有参数的的DayTeam方法
//object[] o = new object[] { "b2b" };
object mystr = mi.Invoke(o, null);
using System;
using System.Collections.Generic;
using System.Reflection;
public class MyClass
{
public static void Main()
{
Person p = new Person();
Type type = p.GetType(); // or Type type = Type.GetType("ModuleFun.Module,ModuleFun");
object o = Activator.CreateInstance(type, new object[] { "miaomiao"});
MethodInfo mi = type.GetMethod("SayHello");
object mystr = mi.Invoke(o, null);
Console.WriteLine(mystr.ToString());
}
}
public class Person
{
private string username;
public Person(){}
public Person(string name){
username = name;
}
public string SayHello(){
return "hello,"+username;
}
}
dll里的命名空间ModuleFun下有两个类
一个是Module
一个是ModuleContent
ModuleContent构造函数需要一个Module对象初始化
Type ModuleContenttype = Type.GetType("ModuleFun.ModuleContent,ModuleFun"); object moduleContent = Activator.CreateInstance(ModuleContenttype,null);
object module = Activator.CreateInstance(Moduletype,moduleContent); MethodInfo mi = Moduletype.GetMethod("DayTeam");string result = (string)mi.Invoke(module, null);
ModuleContent content = new ModuleContent(module);
Type type = content.GetType();
object o = Activator.CreateInstance(type, new object[] { module });
MethodInfo mi = type.GetMethod("Test");
object mystr = mi.Invoke(o, null);
Response.Write(mystr.ToString());
不就是这个意思么 不可以 哎