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等 ...
随机推荐
- iso8583报文自学笔记
一.8583报文组成 TPDU 报文头 应用数据 ISO8583 Msg ID 目的 地址 源地址 应用类别定义 软件 总版本号 终端 状态 处理 要求 保留使用(软件分版本号) 交易数据 60H N ...
- C. Mobile phones
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- Cache的原理、设计及实现
Cache的原理.设计及实现 前言 虽然CPU主频的提升会带动系统性能的改善,但系统性能的提高不仅仅取决于CPU,还与系统架构.指令结构.信息在各个部件之间的传送速度及存储部件的存取速度等因素有关,特 ...
- C# 递归程序 获取某个节点下的全部子节点
/// <summary> /// 获取组织结构树 /// </summary> /// <param name="list"></par ...
- 【Linux/Ubuntu学习6】unbuntu 下载android源码
在Windows下安装Cygwin,通过Cygwin也可在Windows里通过本文的下载步骤下载Android源码. 以下为在Ubuntu下下载Google Android4.4源码的步骤: 1. 安 ...
- OnTouchListener事件监听实现方式之GestureDetector
当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等. 一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouc ...
- android网络请求之get方法
package com.jredu.helloworld.activity; import android.os.Bundle; import android.os.Handler; import a ...
- Android学习笔记④——页面的布局方式
FrameLayout(帧布局) 这个布局的特点是简单的默认把每一个视图组件都放在边框内且放在左上角,即使添加多个视图组件,他们也都是重叠在左上角,新的视图会遮挡住旧的视图.可以根据gravity来改 ...
- 重构16-Encapsulate Conditional(封装条件)
当代码中充斥着若干条件判断时,代码的真正意图会迷失于这些条件判断之中.这时我喜欢将条件判断提取到一个易于读取的属性或方法(如果有参数)中.重构之前的代码如下: ) { return "doS ...
- chrom浏览器避免弹出“确定要离开此面吗?”提示框
一.避免弹出提示框 在网上搜了很多,答案大都是设置window.onbeforeunload=null ,但是试用之后无效. 这个问题放了两天之后返回来再次想,终于找到了答案,在此和大家分享一下: 解 ...