本文摘自PHP中文网,作者巴扎黑,侵删。
这篇文章主要为大家详细介绍了.NET CORE动态调用泛型方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下本文实例为大家分享了.NET CORE动态调用泛型方法,供大家参考,具体内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System;
using System.Reflection;
namespace DynamicCall
{
class Program
{
static void Main( string [] args)
{
Console.WriteLine( "Hello World!" );
Program p = new Program();
var ti = p.GetType().GetTypeInfo();
var mtd = ti.GetMethod( "Get" );
Console.WriteLine(mtd?.ToString() ?? "no get method." );
var genMethod = mtd.MakeGenericMethod( typeof ( int ));
var obj = genMethod.Invoke(p, new object [] { });
Console.WriteLine(obj?.ToString() ?? "no get result." );
Console.ReadLine();
}
public string Get<T>()
{
return typeof (T).FullName;
}
}
}
|
以上就是.NET CORE如何动态调用泛型解决方法的详细内容!
相关阅读 >>
.net的错误处理机制是什么
c#实现与现有.net事件桥接的简单代码
.net core 和 .net .framework 相比哪个速度快?
asp.net core中间件设置教程(7)_实用技巧
asp.net core实例详解三(新建项目)
.net core中如何使用ref和span<t>提高程序性能的实现代码
c#中关于list<t>的并集与交集以及差集解析
.net中抽象类实现多态
oracle clob字段过长保存出错改如何解决?
.net中怎么实现程序分页
更多相关阅读请进入《.net》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » .NET CORE如何动态调用泛型解决方法