Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Returns a MethodInfo of the given type by passing in the string name of it. If it is not yet unboxed, unbox it. Subsequent requests will be faster.
- /// </summary>
- /// <param name="t"></param>
- /// <param name="methodName"></param>
- /// <returns></returns>
- public static MethodInfo TryGetMethod(Type t, string methodName)
- {
- if (!dictUnboxedMethods.TryGetValue(t, out Dictionary<string, MethodInfo> dictMethodsOfType))
- {
- dictUnboxedMethods[t] = new Dictionary<string, MethodInfo>();
- dictMethodsOfType = dictUnboxedMethods[t];
- }
- if (dictMethodsOfType.TryGetValue(methodName, out MethodInfo checkMethod))
- {
- return checkMethod;
- }
- // We haven't unboxed the method yet, unbox it now.
- checkMethod = t.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
- if (checkMethod == null)
- {
- var allMethods = t.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
- Debug.Log($"Available methods on {t.Name}: {string.Join(", ", allMethods.Select(m => m.Name))}");
- Debug.LogError("Could not find method " + methodName + "!");
- return null;
- }
- dictMethodsOfType.Add(methodName, checkMethod);
- return checkMethod;
- }
Advertisement
Add Comment
Please, Sign In to add comment