Home >Backend Development >C#.Net Tutorial >How .NET CORE dynamically calls generic solutions
This article mainly introduces .NET CORE to dynamically call generic methods in detail. It has certain reference value. Interested friends can refer to it.
The examples in this article share .NET with everyone. CORE dynamically calls generic methods for your reference. The specific content is as follows
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; } } }
The above is the detailed content of How .NET CORE dynamically calls generic solutions. For more information, please follow other related articles on the PHP Chinese website!