关闭页面特效

StructureMap.dll 中的 GetInstance 重载 + 如何利用 反射动态创建泛型类

public static T GetInstance<T>(ExplicitArguments args); // // Summary: // Creates a new instance of the requested type T using the supplied Instance. // Mostly used internally // // Parameters: // instance: public static T GetInstance<T>(Instance instance); // // Summary: // Creates or finds the default instance of the pluginType // // Parameters: // pluginType: public static object GetInstance(Type pluginType); // // Summary: // Creates a new instance of the requested type using the supplied Instance. // Mostly used internally // // Parameters: // targetType: // // instance: public static object GetInstance(Type targetType, Instance instance);

 

用 反射动态 创建泛型类的方法 :

var d1 = Type.GetType("GenericTest.TaskA`1"); // GenericTest was my namespace, add yours Type[] typeArgs = { typeof(Item) }; var makeme = d1.MakeGenericType(typeArgs); object o = Activator.CreateInstance(makeme);

 


__EOF__

作  者ღKawaii
出  处https://www.cnblogs.com/kmsfan/p/4560606.html
关于博主:一个普通的小码农,为了梦想奋斗
版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!

posted @   yangliwen  阅读(500)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
0
0
关注
跳至底部
document.getElementById("homeTopTitle").innerText="ღKawaii";
点击右上角即可分享
微信分享提示