using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Winfrom
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
} private void Form4_Load(object sender, EventArgs e)
{
Assembly asm = Assembly.Load("Winfrom");
var type = asm.GetType("Winfrom.Test"); var instance = asm.CreateInstance("Winfrom.Test"); type.GetProperty("Name").SetValue(instance, "hello world", null);
type.GetProperty("Id").SetValue(instance, , null); var method = type.GetMethod("Hello");
method.Invoke(instance, null); }
} public class Test
{
private int id;
private string name; public int Id
{
get { return this.id; }
set { this.id = value; }
} public string Name
{
get { return this.name; }
set { this.name = value; }
} public void Hello()
{
MessageBox.Show(Name);
}
}
}
 protected static List<Tuple<string, object, object>> AssembleyCache = new List<Tuple<string, object, object>>();

                        object myObj = null;
MethodInfo myMethod = null; if (AssembleyCache.Exists(c => c.Item1 == labelMethod))
{
myObj = AssembleyCache.First(c => c.Item1 == labelMethod).Item2;
myMethod = (MethodInfo)AssembleyCache.First(c => c.Item1 == labelMethod).Item3;
}
else
{
Assembly assembly = Assembly.Load("Yanwen.Online.Common.Print");
Type type = assembly.GetType("Yanwen.Online.Common.Print.CreatPdfUtil"); myMethod = type.GetMethod(方法名称);
myObj = Activator.CreateInstance(type, null); AssembleyCache.Add(new Tuple<string, object, object>(方法名称, myObj, myMethod));
}
if (myObj != null)
{
object[] parameter = { expressTypeModel };
var result = myMethod.Invoke(myObj, parameter);
stream = (MemoryStream)result;
}

Assembly(程序集) 反射和缓存的更多相关文章

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

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

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

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

  3. 反射+泛型+缓存 ASP.NET的数据层通用类

    using System; using System.Collections.Generic; using System.Text; using System.Reflection ; using S ...

  4. C# 程序集反射

    namespace AssemblyLibrary { public class AssemblyLibrary { public static object LoadAssembly(string ...

  5. 将dll程序集添加到缓存里

    1.点击开始---所有程序---...如下图 并以管理员身份运行. 2.输入命令行 gacutil.exe /i D:\Word\CRS_BPM_Sln\SourceCode\BPM\Referenc ...

  6. [转]C#反射-Assembly.Load、LoadFrom与LoadFile进阶

    关于.NET中的反射,常用的有三个方法: Assembly.Load()Assembly.LoadFrom()Assembly.LoadFile() 下面说说这三个方法的区别和一些细节问题 1. As ...

  7. C#中的反射 Assembly.Load() Assembly.LoadFrom()

    一些关于C#反射的知识,估计也就最多达到使用API的程度,至于要深入了解,以现在的水平估计很难做到,所以下面此篇文章,以作为一个阶段的总结. 对于反射的总结,我想从以下几个方面展开,首先是反射程序集, ...

  8. 工厂模式Assembly.Load(path).CreateInstance 反射出错解决办法

    项目结构: DALFactory 反射代码反射 //使用缓存 private static object CreateObject(string AssemblyPath,string classNa ...

  9. C#反射Assembly 详细说明

    1.对C#反射机制的理解2.概念理解后,必须找到方法去完成,给出管理的主要语法3.最终给出实用的例子,反射出来dll中的方法 反射是一个程序集发现及运行的过程,通过反射可以得到*.exe或*.dll等 ...

随机推荐

  1. 3.3html学习笔记之链接

    iframe 元素会创建包含另外一个文档的内联框架 <iframe src=""/> 跳转链接 <a href="#here" target= ...

  2. Coin Test

    描述 As is known to all,if you throw a coin up and let it droped on the desk there are usually three r ...

  3. 1.6.5 Updating Parts of Documents

    1. Updating Parts of Documents 有时候你想要直接改变solr文档中的部分内容,solr有两种合适的方法来改变. 第一种:自动更新,这个方法允许仅仅改变文档的一个或者几个字 ...

  4. 1.4.2 solr字段类型--(1.4.2.4)使用Dates(日期)

    1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...

  5. SQL中Len与DataLength区别

    SQL中求字符串长度问题 一.LEN(Param) 求字符串的长度 DataLength(param) 求字符串所占的字节长度 二.LEN不返回文本之后的空格长度 而DataLenth则不同 三.针对 ...

  6. CALayer实现遮罩效果

    #import "ViewController.h" @interface ViewController () @property(nonatomic,strong)CALayer ...

  7. 【Mood-11】值得学习的国内外Android开发者信息

    国内 Android 开发者信息: 昵称 GitHub 博客 介绍 罗升阳   Luoshengyang@csdn Android 源码分析 邓凡平   innost@csdn 阿拉神农 魏祝林   ...

  8. 【原创】利用C++ RAII技术自动回收堆内存

    [说明]这篇文章本来发布在我个人网站的博客上,但由于:1,打算以cnblogs为家了:2. 关于智能指针部分需要修订,所有将修订版发在这里,作为第一篇文章. 常遇到的动态内存回收问题 在C++的编程过 ...

  9. jquery.validate.js实例演示

    validate是前端重要的交互手段,提升性能的同时更能提升用户操作体验,validate的实现大概有三种方式:HTML5部分支 持,validate验证框架,手动写js或ajax调用接口.使用val ...

  10. Zend Studio 上 安装使用Aptana插件(html,css,js代码提示功能) .

    最近装了zend studio 9.0 用了段时间发现写html,css,js代码没提示,要开dreamwaver(对js代码提示也不好).就网上搜索了下,发现了Aptana插件,装上用了下,感觉不错 ...