I have a cache based on
Dictionary
The key is rendered from MethodBase.GetCurrentMethod. Everything worked fine unti
Use MakeGenericMethod, if you can:
using System;
using System.Collections.Generic;
using System.Reflection;
class Program
{
static Dictionary<MethodBase, string> cache = new Dictionary<MethodBase, string>();
static void Main()
{
Method1(default(int));
Method1(default(string));
Console.ReadLine();
}
static void Method1<T>(T g)
{
var m1 = (MethodInfo)MethodBase.GetCurrentMethod();
var genericM1 = m1.MakeGenericMethod(typeof(T)); // <-- This distinguishes the generic types
cache[genericM1] = "m1:" + typeof(T);
}
}
This is not possible; a generic method has a single MethodBase; it doesn't have one MethodBase per set of generic arguments.