Assembly(程序集) 反射和缓存
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(程序集) 反射和缓存的更多相关文章
- IOC容器特性注入第一篇:程序集反射查找
学习kooboo的框架发现它的注入容器方法比较特别,同样是利用MVC的注入点,但它是查找网站下面bin所有的DLL利用反射查找特性找到对应的服务注入到容器. 这样的好处很简单:完全可以不用关心IOC容 ...
- Type.GetType()在跨程序集反射时返回null的解决方法
在开发中,经常会遇到这种情况,在程序集A.dll中需要反射程序集B.dll中的类型.如果使用稍有不慎,就会产生运行时错误.例如使用Type.GetType("BNameSpace.Class ...
- 反射+泛型+缓存 ASP.NET的数据层通用类
using System; using System.Collections.Generic; using System.Text; using System.Reflection ; using S ...
- C# 程序集反射
namespace AssemblyLibrary { public class AssemblyLibrary { public static object LoadAssembly(string ...
- 将dll程序集添加到缓存里
1.点击开始---所有程序---...如下图 并以管理员身份运行. 2.输入命令行 gacutil.exe /i D:\Word\CRS_BPM_Sln\SourceCode\BPM\Referenc ...
- [转]C#反射-Assembly.Load、LoadFrom与LoadFile进阶
关于.NET中的反射,常用的有三个方法: Assembly.Load()Assembly.LoadFrom()Assembly.LoadFile() 下面说说这三个方法的区别和一些细节问题 1. As ...
- C#中的反射 Assembly.Load() Assembly.LoadFrom()
一些关于C#反射的知识,估计也就最多达到使用API的程度,至于要深入了解,以现在的水平估计很难做到,所以下面此篇文章,以作为一个阶段的总结. 对于反射的总结,我想从以下几个方面展开,首先是反射程序集, ...
- 工厂模式Assembly.Load(path).CreateInstance 反射出错解决办法
项目结构: DALFactory 反射代码反射 //使用缓存 private static object CreateObject(string AssemblyPath,string classNa ...
- C#反射Assembly 详细说明
1.对C#反射机制的理解2.概念理解后,必须找到方法去完成,给出管理的主要语法3.最终给出实用的例子,反射出来dll中的方法 反射是一个程序集发现及运行的过程,通过反射可以得到*.exe或*.dll等 ...
随机推荐
- FileListEntityProcessor
一个简单的实体处理程序,可以用于枚举标准文件系统中的文件列表,它不需要使用DataSource.属性如下: fileName:(必填) 用正则表达式来标记文件名 baseDir:(必填) 基础目录,绝 ...
- SQL中Len与DataLength区别
SQL中求字符串长度问题 一.LEN(Param) 求字符串的长度 DataLength(param) 求字符串所占的字节长度 二.LEN不返回文本之后的空格长度 而DataLenth则不同 三.针对 ...
- IOS开发之上传APP
IOS开发最终都会上传APP,但是当我们做好一个项目后.在上传AppStore上的时候往往会被各种原因打回来.让人蛋疼无比. 于是总结了比较容易出现项目被打回容易出现的原因 1.程序崩溃会被打回 这个 ...
- [转]在PHP语言中使用JSON
本文转自:http://www.ruanyifeng.com/blog/2011/01/json_in_php.html 作者: 阮一峰 日期: 2011年1月14日 目前,JSON已经成为最流行的数 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- BZOJ 3083: 遥远的国度 dfs序,树链剖分,倍增
今天再做一天树的题目,明天要开始专攻图论了.做图论十几天之后再把字符串搞搞,区域赛前再把计几看看. 3083: 遥远的国度 Time Limit: 10 Sec Memory Limit: 128 ...
- GDB使用
1.display val 设置显示格式 2.i b显示所有断点
- Macbook之用brew安装Python
1. brew install python 2.If you don't have ~/.bash_profile, add ~/.bash_profile by touch ~/.bash_pro ...
- 如何下载免费英特尔® 实感™ SDK
英特尔® 实感™ SDK支持的用途包括手/指跟踪.面部分析.语音识别和合成.背景分段.增强现实性等等,给你带来全新的人机交互体验.还不赶紧跟着我们一起免费下载英特尔® 实感™ SDK吧! 1. 输入网 ...
- FreeBSD修改root密码错误passwd: pam_chau(www.111cn.net)thtok(): error in service module from:http://www.111cn.net/sys/freebsd/66713.htm
在FreeBSD中修改帐号密码有时候会出现一些错误,针对passwd: pam_chauthtok(): error in service module这样的错误提示,简单整理了以下解决方案:错误提示 ...