Assembly(程序集) 反射和缓存
2024-10-18 10:36:08
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;
}
最新文章
- rabiitmq集群完整安装
- redis入门指南-安装redis
- js中的this和apply
- Python(2.7.6) ConfigParser - 读写配置文件
- Ncurses <;一>;
- Bone Collector(01背包+记忆化搜索)
- Struts2中获取HttpServletRequest,HttpSession等的几种方式
- 【C/C++学院】(24)Oracle数据库编程--管理oracle
- Python安装httplib2 0.9.2
- 两台机子的repcached Memcache 的安装与实验
- php调用API支付接口(使用第三方接口,调用的天工接口。)
- OVS + dpdk 安装与实验环境配置
- graph_base_pic_segmentation里面的细节和代码
- BZOJ3309 DZY Loves Maths 莫比乌斯反演、线性筛
- 在Python中用Selenium执行JavaScript
- js学习——基础知识
- R语言:recommenderlab包的总结与应用案例
- <;记录>; axios 模拟表单提交数据
- 高并发秒杀系统方案(集成Mybatis和Redis)
- nyoj299——如何优雅的写矩阵快速幂