Output: Don't emit unnecessary scope on explicit interface implementations of methods and properties

This commit is contained in:
Katy Coe
2019-11-17 23:38:47 +01:00
parent 22d85ce683
commit 10dfc60344
3 changed files with 25 additions and 3 deletions

View File

@@ -261,7 +261,7 @@ namespace Il2CppInspector
// Non-indexer
if ((!prop.CanRead || !prop.GetMethod.DeclaredParameters.Any()) && (!prop.CanWrite || prop.SetMethod.DeclaredParameters.Count == 1))
sb.Append($"{prop.Name} {{ ");
sb.Append($"{prop.CSharpName} {{ ");
// Indexer
else
sb.Append("this[" + string.Join(", ", primary.DeclaredParameters.SkipLast(getAccess >= setAccess? 0 : 1)

View File

@@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace Il2CppInspector.Reflection
{
@@ -53,7 +54,21 @@ namespace Il2CppInspector.Reflection
public string CSharpName =>
// Operator overload or user-defined conversion operator
OperatorMethodNames.ContainsKey(Name)? "operator " + OperatorMethodNames[Name] : Name;
OperatorMethodNames.ContainsKey(Name)? "operator " + OperatorMethodNames[Name]
// Explicit interface implementation
: (IsVirtual && IsFinal && (Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot)?
((Func<string>)(() => {
var implementingInterface = DeclaringType.ImplementedInterfaces.FirstOrDefault(i => Name.StartsWith(Regex.Replace(i.FullName, @"`\d", "").Replace('[', '<').Replace(']', '>') + "."));
// Regular interface implementation
if (implementingInterface == null)
return Name;
var sliceLength = Regex.Replace(implementingInterface.FullName, @"`\d", "").Length + 1;
return implementingInterface.CSharpName + "." + Name.Substring(sliceLength);
}))()
// Regular method
: Name;
protected MethodBase(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(declaringType) {
Definition = pkg.Methods[methodIndex];
@@ -120,7 +135,7 @@ namespace Il2CppInspector.Reflection
{ IsConstructor: true, IsStatic: true } => "",
// Explicit interface implementations do not have an access level modifier
{ Name: var name } when name.IndexOf('.') != -1 => "",
{ IsVirtual: true, IsFinal: true, Attributes: var a } when (a & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot => "",
{ IsPrivate: true } => "private ",
{ IsPublic: true } => "public ",

View File

@@ -26,6 +26,13 @@ namespace Il2CppInspector.Reflection {
public override string Name { get; protected set; }
public string CSharpName =>
// Explicit interface implementation
Name.IndexOf('.') != -1? string.Join('.', Name.Split('.')[^2..])
// Regular method
: Name;
public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[^1].ParameterType;
public override MemberTypes MemberType => MemberTypes.Property;