C#: Sanitize method names (#70)

This commit is contained in:
Katy Coe
2020-09-14 12:25:52 +02:00
parent fcbfc65204
commit 47cd6b928b

View File

@@ -103,13 +103,14 @@ namespace Il2CppInspector.Reflection
var implementingInterface = DeclaringType.ImplementedInterfaces.FirstOrDefault(i => Name.StartsWith(i.Namespace + "." + i.CSharpName + ".")) var implementingInterface = DeclaringType.ImplementedInterfaces.FirstOrDefault(i => Name.StartsWith(i.Namespace + "." + i.CSharpName + "."))
?? DeclaringType.ImplementedInterfaces.FirstOrDefault(i => Name.StartsWith(i.Namespace + "." + i.GetCSharpTypeDeclarationName().Replace(" ", "") + ".")); ?? DeclaringType.ImplementedInterfaces.FirstOrDefault(i => Name.StartsWith(i.Namespace + "." + i.GetCSharpTypeDeclarationName().Replace(" ", "") + "."));
// TODO: There are some combinations we haven't dealt with so use this test as a safety valve // TODO: There are some combinations we haven't dealt with so use this test as a safety valve
// Don't call ToCIdentifier() because this still does definitely implement an interface, we just don't know which
if (implementingInterface == null) if (implementingInterface == null)
return Name; return Name;
return implementingInterface.CSharpName + Name.Substring(Name.LastIndexOf('.')); return implementingInterface.CSharpName + "." + Name.Substring(Name.LastIndexOf('.') + 1).ToCIdentifier();
}))() }))()
// Regular method // Regular method
: Name; : Name.ToCIdentifier(allowScopeQualifiers: true);
// Initialize a method from a method definition (MethodDef) // Initialize a method from a method definition (MethodDef)
protected MethodBase(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(declaringType) { protected MethodBase(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(declaringType) {