Yes, you can call CacheManager.CodeLookup using reflection.
Based on the code you shared, it will be something like this:
Type containingType = typeof (CacheManager); var method = containingType.GetMethod("CodeLookup", BindingFlags.Static | BindingFlags.Public, null, new Type[0], new ParameterModifier[0]); var concreteMethod = method.MakeGenericMethod(targetType); Dictionary<string,int> codes = (Dictionary<string,int>)concreteMethod.Invoke(null, null);
You might want to cache a concreteMethod instance for each targetType, if you use a lot method, reflection can be expensive in terms of performance.
Edit : when a method is overloaded to fit a specific overload; use the GetMethod overload, which allows you to specify the exact parameters, skipping in an empty array (since the overload you want to call has no parameters). Sample code updated.
driis source share