namespace AssemblyLibrary
{
public class AssemblyLibrary
{
public static object LoadAssembly(string filePath,string nameSpace,string typeName,string methodName,object[] parameters)
{
try
{
byte[] filesByte = File.ReadAllBytes(filePath);
Assembly assembly = Assembly.Load(filesByte);
System.Type[] types = assembly.GetTypes();
foreach (System.Type dllType in types)
{
if (dllType.Namespace == nameSpace && dllType.Name == typeName)
{
Type type = assembly.GetType(nameSpace + "." + typeName);
object obj = System.Activator.CreateInstance(type);
MethodInfo methodInfo = type.GetMethod(methodName);
if (methodInfo != null)
{
return methodInfo.Invoke(obj, parameters);
}
}
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
private void btnExecte_Click(object sender, EventArgs e)
{
try
{
if (this.txtPathFile.Text.Trim() == "")
{
MessageBox.Show("请输入相关查询条件!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
return;
}
object obj = AssemblyLibrary.AssemblyLibrary.LoadAssembly(this.txtPathFile.Text,"TestLibrary", "TestLibrary", "GetMethod", new object[] { this.txtParameters.Text });
          if (obj != null) { MessageBox.Show(obj.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question); }
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  }
}
namespace TestLibrary
{
public class TestLibrary
{
public string GetMethod(string parm)
{
switch (parm)
{
case "":
return "";
case "":
return "";
case "":
return "";
default:
return "";
}
}
}
}

C# 程序集反射的更多相关文章

  1. IOC容器特性注入第一篇:程序集反射查找

    学习kooboo的框架发现它的注入容器方法比较特别,同样是利用MVC的注入点,但它是查找网站下面bin所有的DLL利用反射查找特性找到对应的服务注入到容器. 这样的好处很简单:完全可以不用关心IOC容 ...

  2. Type.GetType()在跨程序集反射时返回null的解决方法

    在开发中,经常会遇到这种情况,在程序集A.dll中需要反射程序集B.dll中的类型.如果使用稍有不慎,就会产生运行时错误.例如使用Type.GetType("BNameSpace.Class ...

  3. Assembly(程序集) 反射和缓存

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. C#- 反射之 GetType()方法

    Type.GetType()在跨程序集反射时返回null的解决方法 在开发中,经常会遇到这种情况,在程序集A.dll中需要反射程序集B.dll中的类型.如果使用稍有不慎,就会产生运行时错误.例如使用T ...

  5. 读书笔记—CLR via C#反射

    前言 这本书这几年零零散散读过两三遍了,作为经典书籍,应该重复读反复读,既然我现在开始写博了,我也准备把以前觉得经典的好书重读细读一遍,并且将笔记整理到博客中,好记性不如烂笔头,同时也在写的过程中也可 ...

  6. Java基础之 反射是什么?

    什么是反射,反射能干嘛? 反射是:指程序可以访问.检测和修改它本身状态或行为的一种能力 反射是一种能力,所以给的定义就是说明了它能干嘛. 我们平时用反射主要做: 获取类型的相关信息 动态调用方法 动态 ...

  7. C#-反射reflection

    目录 简介 引入 1.新建类库 2. 类库的使用 3.反射 反射实例1 反射实例2 反射实例3 C# shanzm 简介 反射(reflection)是什么? 在<精通C#>中是这么说的& ...

  8. net 反射30分钟速成

    概述 什么是反射 Reflection,中文翻译为反射.        这是.Net中获取运行时类型信息的方式,.Net的应用程序由几个部分:‘程序集(Assembly)’.‘模块(Module)’. ...

  9. 【.Net】net 反射15分钟速成

    概述 什么是反射 Reflection,中文翻译为反射.        这是.Net中获取运行时类型信息的方式,.Net的应用程序由几个部分:‘程序集(Assembly)’.‘模块(Module)’. ...

随机推荐

  1. php基础知识(1)

    1.判断变量是否存在isset() $v1="a"; if(!isset($v1)){ echo "变量存在"; }else{ echo "变量不存在 ...

  2. 40 个顶级 jQuery 图片、内容滑块和幻灯片(转)

    在这个快速发展的网络世界中,我们使用图片.内容滑块和幻灯片来给网站实现良好.有吸引力的外观.你可以吸引浏览者借助图像滑块让网站更加具有活力.使用 JavaScript 可以轻松实现轻量级的图片和内容滑 ...

  3. 关于VSS配置遇到的问题及解决方法

    今天安装网上的教程开始部署源代码管理器 相关工具 VSS安装包:http://url.cn/PolkN8 VSS汉化包:http://url.cn/PeHq1A 具体安装教程请参考:http://ww ...

  4. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  5. Determining Equality of Objects

    [Determining Equality of Objects] If you need to determine whether one object is the same as another ...

  6. qq邮箱发送

    454 Authentication failed, please open smtp flag first!用QQ邮箱测试报错 我用QQ邮箱测试javamail发送邮件的功能,用户名密码设置正确,却 ...

  7. Mongo数据模型

    Mongo数据模型 一个Mongo系统(参考上述部署)包含一组数据库 一个 database 包含一组collection 一个 collection 包含一组document 一个 document ...

  8. poj 3134 Power Calculus(IDA*)

    题目大意: 用最小的步数算出  x^n 思路: 直接枚举有限步数可以出现的所有情况. 然后加一个A*   就是如果这个数一直平方  所需要的步骤数都不能达到最优   就剪掉 #include < ...

  9. Binary Search

    Binary Search                              [原文见:http://www.topcoder.com/tc?module=Static&d1=tuto ...

  10. jeecg团队招新人(5人)

    jeecg团队招新人(5人) http://www.jeecg.org/forum.php? mod=viewthread&tid=2046&page=1&extra=#pid ...