1.使用反射的好处?2.Assembly类怎么获取第三方dll中类的对象?
解决方案 »
- html form表单submit提交给wcf端接收不到json只能接收到xml格式的数据
- 有没有一种散列集合可以添加重复的KEY
- C# 操作Excel怎么把一个Cell设置成下拉框。
- NHibernate 读配置诡异现象
- 为什么显示不了我要的图了~~~
- C#调用VC++的DLL,函数参数或返回值为CString
- WCF程序想把.exe.config给放到更新包里,让客户端更新这个配置文件,跪求解决方案!!!!
- 为什么读不出App.Config中的信息?
- 在先等待,一个简单的查询问题,解决马上给分!
- 关于TreeView的滚动条?
- ---为什么一个Thread中的方法不能调用另一个Thread中的方法?而Control.BeginInvoke中确能实现这样的调用,原因是什么?能介绍一下吗?
- 在dataset中怎么運用update語句啊???
2.Assembly..::.GetTypes 方法可以获得类型
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
ParameterInfo[] Params = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System.String
// Position = 0
// Optional=False
foreach (ParameterInfo Param in Params)
{
Console.WriteLine("Param=" + Param.Name.ToString());
Console.WriteLine(" Type=" + Param.ParameterType.ToString());
Console.WriteLine(" Position=" + Param.Position.ToString());
Console.WriteLine(" Optional=" + Param.IsOptional.ToString());
}
object ob = Activator.CreateInstance(t);如果下面我要用这个dll中的方法,我必须要将 ob 强制类型转换一下才可以用
但我不知道这个类名是什么,怎么转换?(这个dll文件不是用C#写的)
assembly只能装在.Net的dll
Activator.CreateInstance(t).Unwrap()
没有Unwrap() 方法
像你那个object ob = Activator.CreateInstance(t); 如果没有基类或者接口,就不能再转换了,只能通过反射Invoke
得这样:
MethodInfo mi=t.GetMothod(....)
mi.GetParameters(...)
mi.Invoke(....
这样来调用