关于反射

xiaosong8023 2010-01-17 11:47:45
请问各位大大,要怎么才能反射.net中的内置对象,如:System.Data.SqlClient.SqlDataAdapter
...全文
80 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianliang1 2010-01-17
  • 打赏
  • 举报
回复
up
xiaosong8023 2010-01-17
  • 打赏
  • 举报
回复
d
xiaosong8023 2010-01-17
  • 打赏
  • 举报
回复
还要找到SqlDataAdapter的.dll文件吗?
wzp144650 2010-01-17
  • 打赏
  • 举报
回复
用反射调用那个DLL
江南小鱼 2010-01-17
  • 打赏
  • 举报
回复
给你个例子,自己参考做。

使用反射查看某个dll文件的实现

string _strPath = AppDomain.CurrentDomain.BaseDirectory;

string str = _strPath + "Platform.dll";

Assembly m_Assembly = Assembly.LoadFrom(str);//载入装配件


//枚举一个dll下的成员

static void EnumCls(Assembly m_Assembly)

{

Type[] types = m_Assembly.GetTypes();

foreach (Type t in types)

{

Console.WriteLine(t.Name);

}

}

使用反射调用某个dll文件下的方法

string str = _strPath + "BLL.dll";

Assembly m_Assembly = Assembly.LoadFrom(str);//载入装配件

string clsName = "Bll";

object o = ActivetorMethodOutObject(clsName, m_Assembly);//返回装配件下的类

Bll bl = (Bll)o;

bl.Greeting();

//返回指定dll下的类

static object ActivetorMethodOutObject(string clsName,Assembly m_Assembly)

{

object _result = null;

try

{

string _tmpCls = "BLL." + clsName;

Type _CurrentType = m_Assembly.GetType(_tmpCls,false);

_result = Activator.CreateInstance(_CurrentType);

}

catch { }

return _result;

}

BLL.dll

using System;

using System.Collections.Generic;

using System.Text;


namespace BLL

{

public class Bll

{

public void Greeting()

{

Console.WriteLine("Hello from your classmate DongYi Wang,who is now working in ShangHai " +

"as a coder,he sometimes miss you very much.How time flies,it's almost 4 years since " +

"the last meet.Thanks for your gift.Remember me to your family and wish you success." +

"Enjoy every day.Keep touching.yours sincerely.");

}

}

}

Reflector工具可以很方便的反射dll文件

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧