修复 ReflectionCompatibilityDetector处理Enum.TryParse<T>,并且T包含泛型参数时抛出异常的bug
parent
0fe0a91793
commit
b84d158fac
|
@ -190,20 +190,28 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
private void AnalyzeEnum(IMethod method, TypeDef typeDef)
|
||||
{
|
||||
const int extraSearchInstructionCount = 3;
|
||||
TypeDef parseType = GetMethodGenericParameter(method)?.ToTypeDefOrRef()?.ResolveTypeDef();
|
||||
TypeSig parseTypeSig = GetMethodGenericParameter(method);
|
||||
TypeDef parseType = parseTypeSig?.ToTypeDefOrRef().ResolveTypeDef();
|
||||
switch (method.Name)
|
||||
{
|
||||
case "Parse":
|
||||
{
|
||||
if (parseType != null)
|
||||
if (parseTypeSig != null)
|
||||
{
|
||||
// Enum.Parse<T>(string name) or Enum.Parse<T>(string name, bool caseInsensitive)
|
||||
if (parseType != null)
|
||||
{
|
||||
if (IsAnyEnumItemRenamed(parseType))
|
||||
{
|
||||
Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse<T> field of T:{parseType.FullName} is renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse<T> field of T should not be renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Enum.Parse(Type type, string name) or Enum.Parse(Type type, string name, bool ignoreCase)
|
||||
TypeDef enumType = FindLatestTypeOf(method.GetParamCount() + extraSearchInstructionCount)?.ResolveTypeDef();
|
||||
|
@ -220,15 +228,22 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
}
|
||||
case "TryParse":
|
||||
{
|
||||
if (parseType != null)
|
||||
if (parseTypeSig != null)
|
||||
{
|
||||
// Enum.TryParse<T>(string name, out T result) or Enum.TryParse<T>(string name, bool ignoreCase, out T result)
|
||||
if (parseType != null)
|
||||
{
|
||||
if (IsAnyEnumItemRenamed(parseType))
|
||||
{
|
||||
Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse<T> field of T:{parseType.FullName} is renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse<T> field of T should not be renamed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("impossible");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue