Model: Handle C# method hiding ('new' keyword in method declarations)

This commit is contained in:
Katy Coe
2019-11-09 22:32:32 +01:00
parent 4f54c7a85e
commit 41d2325560
3 changed files with 12 additions and 1 deletions

View File

@@ -21,5 +21,8 @@ namespace Il2CppInspector.Reflection
public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) { }
public override string ToString() => DeclaringType.Name + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")";
public override string GetSignatureString() => Name + GetTypeParametersString()
+ "(" + string.Join(",", DeclaredParameters.Select(x => x.GetSignatureString())) + ")";
}
}

View File

@@ -149,6 +149,12 @@ namespace Il2CppInspector.Reflection
if ((Attributes & MethodAttributes.PinvokeImpl) != 0)
modifiers.Append("extern ");
// Method hiding
if ((DeclaringType.BaseType?.GetAllMethods().Any(m => m.GetSignatureString() == GetSignatureString() && m.IsHideBySig) ?? false)
&& (((Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot && !IsVirtual)
|| (Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot))
modifiers.Append($"new ");
if (Name == "op_Implicit")
modifiers.Append("implicit ");
if (Name == "op_Explicit")
@@ -164,6 +170,8 @@ namespace Il2CppInspector.Reflection
public string GetTypeParametersString() => GenericTypeParameters == null? "" :
"<" + string.Join(", ", GenericTypeParameters.Select(p => p.CSharpName)) + ">";
public abstract string GetSignatureString();
// List of operator overload metadata names
// https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/operator-overloads
public static Dictionary<string, string> OperatorMethodNames = new Dictionary<string, string> {

View File

@@ -31,7 +31,7 @@ namespace Il2CppInspector.Reflection
// TODO: Generic arguments (and on ConstructorInfo)
public override string ToString() => ReturnType.Name + " " + Name + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")";
public string GetSignatureString() => ReturnParameter.GetSignatureString() + " " + Name + GetTypeParametersString()
public override string GetSignatureString() => ReturnParameter.GetSignatureString() + " " + Name + GetTypeParametersString()
+ "(" + string.Join(",", DeclaredParameters.Select(x => x.GetSignatureString())) + ")";
}
}