本文实例为大家分享了.NET CORE动态调用泛型方法,供大家参考,具体内容如下
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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复