动态
来源:互联网 发布:javascript 元素位置 编辑:程序博客网 时间:2024/04/27 06:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
public class BL_DllInvoke
{
object OBJ;//object对象
Assembly MyAssembly;//要处理的程序及对象
List<string> MyAssemblys;//字符串集
public object MethodInvoke(string lpFileName, string ClassName, string lpProcName, object[] ObjArray_Parameter)
{
try
{
string[] nameSpace = ClassName.Split(new char[]{'.'});//字符串处理
if (MyAssembly == null || MyAssembly.GetName().Name != nameSpace[0])
{
MyAssembly = Assembly.LoadFrom(lpFileName);//加载程序集
}
Type[] type = MyAssembly.GetTypes();//得到程序集类型
foreach (Type t in type)
{
if (ClassName.Trim() == t.ToString().Trim())//字符串相等
{// 查找要调用的方法并进行调用
try
{
MethodInfo m = t.GetMethod(lpProcName);//方法信息
if (m != null)//不为空
{
if (OBJ == null || t.FullName != OBJ.ToString())
{
OBJ = Activator.CreateInstance(t);//创建实例
}
return m.Invoke(OBJ, ObjArray_Parameter);//返回要调用的方法
}
else
MessageBox.Show(" 装载出错 !");//弹出错误信息
}
catch (Exception e)
{
//捕获异常
MessageBox.Show(e.Message.ToString());
}
}
}
}
catch (System.NullReferenceException e)
{
//捕获异常
MessageBox.Show(e.Message);
}
return (object)0;//返回
}
public object ConstructorInvoke(string lpFileName, string ClassName,Type[] Constructor_Parameter, object[] ObjArray_Parameter)
{
try
{
//加载程序集
MyAssembly = Assembly.LoadFrom(lpFileName);
//程序集类型
Type[] type = MyAssembly.GetTypes();
foreach (Type t in type)
{// 查找要调用的命名空间及类
if (ClassName.Trim() == t.ToString().Trim())
{// 查找要调用的方法并进行调用
ConstructorInfo c = t.GetConstructor(Constructor_Parameter);//构造函数信息
if (c != null)
{
//创建构造函数对象
OBJ = c.Invoke(ObjArray_Parameter);
return OBJ;//返回对象
}
else
MessageBox.Show(" 装载出错 !");//显示出错信息
}
}
}
catch (System.NullReferenceException e)
{
//输出异常信息
MessageBox.Show(e.Message);
}
return (object)0;//返回空值
}
public object GetField(string lpFileName,string ClassName, string FieldName)
{
try
{
//分解类名字符串,保存到nameSpace中
string[] nameSpace = ClassName.Split(new char[] { '.' });
if ( MyAssembly == null || MyAssembly.GetName().Name != nameSpace[0])//如果为空且程序集的名字不等于ClassName
{
MyAssembly = Assembly.Load(lpFileName);//加载程序集
}
Type[] type = MyAssembly.GetTypes();//获取此程序集中定义的类型
foreach (Type t in type)
{// 查找要调用的命名空间及类
if (ClassName.Trim() == t.ToString().Trim())
{// 得到属性信息
FieldInfo f = t.GetField(FieldName);
if (f != null)
{
if (OBJ == null || t.FullName != OBJ.ToString())
{
OBJ = Activator.CreateInstance(t);//创建实例
}
return f.GetValue(OBJ);//返回成员变量值
}
else
MessageBox.Show(" 装载出错 !");//显示错误信息
}
}
}
catch (System.NullReferenceException e)
{//捕获异常
MessageBox.Show(e.Message);
}
return (object)0;//返回空值
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
public class BL_DllInvoke
{
object OBJ;//object对象
Assembly MyAssembly;//要处理的程序及对象
List<string> MyAssemblys;//字符串集
public object MethodInvoke(string lpFileName, string ClassName, string lpProcName, object[] ObjArray_Parameter)
{
try
{
string[] nameSpace = ClassName.Split(new char[]{'.'});//字符串处理
if (MyAssembly == null || MyAssembly.GetName().Name != nameSpace[0])
{
MyAssembly = Assembly.LoadFrom(lpFileName);//加载程序集
}
Type[] type = MyAssembly.GetTypes();//得到程序集类型
foreach (Type t in type)
{
if (ClassName.Trim() == t.ToString().Trim())//字符串相等
{// 查找要调用的方法并进行调用
try
{
MethodInfo m = t.GetMethod(lpProcName);//方法信息
if (m != null)//不为空
{
if (OBJ == null || t.FullName != OBJ.ToString())
{
OBJ = Activator.CreateInstance(t);//创建实例
}
return m.Invoke(OBJ, ObjArray_Parameter);//返回要调用的方法
}
else
MessageBox.Show(" 装载出错 !");//弹出错误信息
}
catch (Exception e)
{
//捕获异常
MessageBox.Show(e.Message.ToString());
}
}
}
}
catch (System.NullReferenceException e)
{
//捕获异常
MessageBox.Show(e.Message);
}
return (object)0;//返回
}
public object ConstructorInvoke(string lpFileName, string ClassName,Type[] Constructor_Parameter, object[] ObjArray_Parameter)
{
try
{
//加载程序集
MyAssembly = Assembly.LoadFrom(lpFileName);
//程序集类型
Type[] type = MyAssembly.GetTypes();
foreach (Type t in type)
{// 查找要调用的命名空间及类
if (ClassName.Trim() == t.ToString().Trim())
{// 查找要调用的方法并进行调用
ConstructorInfo c = t.GetConstructor(Constructor_Parameter);//构造函数信息
if (c != null)
{
//创建构造函数对象
OBJ = c.Invoke(ObjArray_Parameter);
return OBJ;//返回对象
}
else
MessageBox.Show(" 装载出错 !");//显示出错信息
}
}
}
catch (System.NullReferenceException e)
{
//输出异常信息
MessageBox.Show(e.Message);
}
return (object)0;//返回空值
}
public object GetField(string lpFileName,string ClassName, string FieldName)
{
try
{
//分解类名字符串,保存到nameSpace中
string[] nameSpace = ClassName.Split(new char[] { '.' });
if ( MyAssembly == null || MyAssembly.GetName().Name != nameSpace[0])//如果为空且程序集的名字不等于ClassName
{
MyAssembly = Assembly.Load(lpFileName);//加载程序集
}
Type[] type = MyAssembly.GetTypes();//获取此程序集中定义的类型
foreach (Type t in type)
{// 查找要调用的命名空间及类
if (ClassName.Trim() == t.ToString().Trim())
{// 得到属性信息
FieldInfo f = t.GetField(FieldName);
if (f != null)
{
if (OBJ == null || t.FullName != OBJ.ToString())
{
OBJ = Activator.CreateInstance(t);//创建实例
}
return f.GetValue(OBJ);//返回成员变量值
}
else
MessageBox.Show(" 装载出错 !");//显示错误信息
}
}
}
catch (System.NullReferenceException e)
{//捕获异常
MessageBox.Show(e.Message);
}
return (object)0;//返回空值
}
}
- 动态
- 动态
- 动态
- 动态磁盘&动态卷
- 动态sql,动态游标
- 动态加载动态库
- 动态加载动态库
- 动态规划!!!动态规划!!!
- 动态内存/动态数组
- 动态类型和动态绑定,动态载入
- 动态生成java、动态编译、动态加载
- 动态语言
- 动态装载
- 近期动态
- 动态方法
- 近日动态!
- 动态代理
- 动态Table
- hdwiki/destoon/discuz通过UC整合后会员注册提交后没有跳转解决方法
- VMware Workstation 9上安装MAC OS X Lion 10.8图解
- 善的讯息可以产生美丽的水结晶
- XXXX-BI二期进入试运行了
- 衡量创业智商的几个因素
- 动态
- openfiler 移植记录
- x264 4x4帧内预测代码解析
- 完全用linux工作
- Piwik 网站分析系统
- [Leetcode] Subsets
- 25个最佳最闪亮的Eclipse开发项目
- 《C++面向对象》结构体继承
- iphone 开发之过滤html标签