Update ReflectionUtility.cs

This commit is contained in:
Sinai 2021-05-13 01:06:14 +10:00
parent 275225a284
commit 70d66f93a5

View File

@ -372,39 +372,33 @@ namespace UnityExplorer
if (!methodInfos.ContainsKey(type)) if (!methodInfos.ContainsKey(type))
methodInfos.Add(type, new Dictionary<string, MethodInfo>()); methodInfos.Add(type, new Dictionary<string, MethodInfo>());
var sig = methodName;
if (cacheAmbiguous) if (cacheAmbiguous)
{ {
sig += "|"; methodName += "|";
foreach (var arg in argumentTypes) foreach (var arg in argumentTypes)
sig += arg.FullName + ","; methodName += arg.FullName + ",";
}
else
{
sig += "|" + (argumentTypes?.Length.ToString() ?? "null");
} }
try try
{ {
if (!methodInfos[type].ContainsKey(sig)) if (!methodInfos[type].ContainsKey(methodName))
{ {
if (argumentTypes != null) if (argumentTypes != null)
methodInfos[type].Add(sig, type.GetMethod(methodName, FLAGS, null, argumentTypes, null)); methodInfos[type].Add(methodName, type.GetMethod(methodName, FLAGS, null, argumentTypes, null));
else else
methodInfos[type].Add(sig, type.GetMethod(methodName, FLAGS)); methodInfos[type].Add(methodName, type.GetMethod(methodName, FLAGS));
} }
return methodInfos[type][sig]; return methodInfos[type][methodName];
} }
catch (AmbiguousMatchException) catch (AmbiguousMatchException)
{ {
ExplorerCore.LogWarning($"AmbiguousMatchException trying to get method '{sig}'"); ExplorerCore.LogWarning($"AmbiguousMatchException trying to get method '{methodName}'");
return null; return null;
} }
catch (Exception e) catch (Exception e)
{ {
ExplorerCore.LogWarning($"{e.GetType()} trying to get method '{sig}': {e.Message}\r\n{e.StackTrace}"); ExplorerCore.LogWarning($"{e.GetType()} trying to get method '{methodName}': {e.Message}\r\n{e.StackTrace}");
return null; return null;
} }
} }