Add p prefix if it's a pointer type
This commit is contained in:
parent
9d61d9845d
commit
a0f5a109dd
|
@ -35,6 +35,8 @@ namespace de4dot.renamer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string prefix = getPrefix(typeRef);
|
||||||
|
|
||||||
var elementType = typeRef.GetElementType();
|
var elementType = typeRef.GetElementType();
|
||||||
if (elementType is GenericParameter)
|
if (elementType is GenericParameter)
|
||||||
return genericParamNameCreator.create();
|
return genericParamNameCreator.create();
|
||||||
|
@ -50,11 +52,20 @@ namespace de4dot.renamer {
|
||||||
if (tickIndex > 0)
|
if (tickIndex > 0)
|
||||||
newName = newName.Substring(0, tickIndex);
|
newName = newName.Substring(0, tickIndex);
|
||||||
|
|
||||||
return addTypeName(name, newName).create();
|
return addTypeName(name, newName, prefix).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected INameCreator addTypeName(string fullName, string newName) {
|
string getPrefix(TypeReference typeRef) {
|
||||||
newName = fixName(newName);
|
string prefix = "";
|
||||||
|
while (typeRef is PointerType) {
|
||||||
|
typeRef = ((PointerType)typeRef).ElementType;
|
||||||
|
prefix += "p";
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected INameCreator addTypeName(string fullName, string newName, string prefix = "") {
|
||||||
|
newName = fixName(prefix, newName);
|
||||||
|
|
||||||
var name2 = " " + newName;
|
var name2 = " " + newName;
|
||||||
NameCreator nc;
|
NameCreator nc;
|
||||||
|
@ -65,7 +76,7 @@ namespace de4dot.renamer {
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract string fixName(string name);
|
protected abstract string fixName(string prefix, string name);
|
||||||
|
|
||||||
public virtual TypeNames merge(TypeNames other) {
|
public virtual TypeNames merge(TypeNames other) {
|
||||||
foreach (var pair in other.typeNames) {
|
foreach (var pair in other.typeNames) {
|
||||||
|
@ -77,6 +88,10 @@ namespace de4dot.renamer {
|
||||||
genericParamNameCreator.merge(other.genericParamNameCreator);
|
genericParamNameCreator.merge(other.genericParamNameCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static string upperFirst(string s) {
|
||||||
|
return s.Substring(0, 1).ToUpperInvariant() + s.Substring(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VariableNameCreator : TypeNames {
|
class VariableNameCreator : TypeNames {
|
||||||
|
@ -99,8 +114,7 @@ namespace de4dot.renamer {
|
||||||
addTypeName("System.Decimal", "decimal");
|
addTypeName("System.Decimal", "decimal");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string fixName(string name) {
|
static string lowerLeadingChars(string name) {
|
||||||
// Make all leading upper case chars lower case
|
|
||||||
var s = "";
|
var s = "";
|
||||||
for (int i = 0; i < name.Length; i++) {
|
for (int i = 0; i < name.Length; i++) {
|
||||||
char c = char.ToLowerInvariant(name[i]);
|
char c = char.ToLowerInvariant(name[i]);
|
||||||
|
@ -110,11 +124,18 @@ namespace de4dot.renamer {
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string fixName(string prefix, string name) {
|
||||||
|
name = lowerLeadingChars(name);
|
||||||
|
if (prefix == "")
|
||||||
|
return name;
|
||||||
|
return prefix + upperFirst(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyNameCreator : TypeNames {
|
class PropertyNameCreator : TypeNames {
|
||||||
protected override string fixName(string name) {
|
protected override string fixName(string prefix, string name) {
|
||||||
return name.Substring(0, 1).ToUpperInvariant() + name.Substring(1);
|
return prefix + upperFirst(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user