Skip to content

Commit ed9fdf7

Browse files
authored
Merge 44273fe into f0d6304
2 parents f0d6304 + 44273fe commit ed9fdf7

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Confuser.Renamer/BAML/BAMLAnalyzer.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ void AddTypeSigReference(TypeSig typeSig, INameReference<IDnlibDef> reference) {
261261
}
262262
}
263263

264+
void AddPropertyDefReference(PropertyDef propertyDef, INameReference<PropertyDef> reference) {
265+
service.ReduceRenameMode(propertyDef, RenameMode.Letters);
266+
service.AddReference(propertyDef, reference);
267+
}
268+
264269
void ProcessBAMLElement(BamlElement root, BamlElement elem) {
265270
ProcessElementHeader(elem);
266271
ProcessElementBody(root, elem);
@@ -609,11 +614,17 @@ void AnalyzePropertyPathProperty(PropertyPathPartUpdater part) {
609614
var typeName = part.GetTypeName();
610615
var propertyName = part.GetPropertyName();
611616
if (!string.IsNullOrWhiteSpace(typeName)) {
612-
var sig = ResolveType(typeName, out var prefix);
613-
if (sig != null && context.Modules.Contains((ModuleDefMD) sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module)) {
614-
var reference = new BAMLPathTypeReference(xmlnsCtx, sig, part);
617+
var sig = ResolveType(typeName, out _);
618+
var basicTypeDef = sig?.ToBasicTypeDefOrRef().ResolveTypeDef();
619+
if (!(basicTypeDef is null) && context.Modules.Contains(basicTypeDef.Module as ModuleDefMD)) {
620+
var propDef = basicTypeDef.FindPropertyCheckBaseType(propertyName);
621+
var reference = new BAMLPathTypeReference(xmlnsCtx, sig, propDef, part);
615622
AddTypeSigReference(sig, reference);
616-
return;
623+
624+
if (!(propDef is null)) {
625+
AddPropertyDefReference(propDef, reference);
626+
return; // Return to avoid blocking renaming of the property.
627+
}
617628
}
618629
}
619630

Confuser.Renamer/References/BAMLPathTypeReference.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
using dnlib.DotNet;
88

99
namespace Confuser.Renamer.References {
10-
internal sealed class BAMLPathTypeReference : INameReference<TypeDef> {
10+
internal sealed class BAMLPathTypeReference : INameReference<TypeDef>, INameReference<PropertyDef> {
1111
PropertyPathPartUpdater? PropertyInfo { get; }
1212
PropertyPathIndexUpdater? IndexerInfo { get; }
1313
private readonly TypeSig sig;
14+
readonly PropertyDef prop;
1415
private readonly BAMLAnalyzer.XmlNsContext xmlnsCtx;
1516

1617
public bool ShouldCancelRename => false;
@@ -26,8 +27,10 @@ private BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig) {
2627
public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathIndexUpdater indexerInfo) : this(xmlnsCtx, sig) =>
2728
IndexerInfo = indexerInfo;
2829

29-
public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathPartUpdater propertyInfo) : this(xmlnsCtx, sig) =>
30+
public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyDef property, PropertyPathPartUpdater propertyInfo) : this(xmlnsCtx, sig) {
3031
PropertyInfo = propertyInfo;
32+
prop = property;
33+
}
3134

3235
public bool UpdateNameReference(ConfuserContext context, INameService service) {
3336
string name = sig.ReflectionName;
@@ -43,7 +46,7 @@ public bool UpdateNameReference(ConfuserContext context, INameService service) {
4346
else {
4447
Debug.Assert(PropertyInfo != null, nameof(PropertyInfo) + " != null");
4548
var info = PropertyInfo.Value;
46-
var propertyName = info.GetPropertyName();
49+
var propertyName = prop?.Name ?? info.GetPropertyName();
4750
var newName = string.Format(CultureInfo.InvariantCulture, "({0}.{1})", name, propertyName);
4851
if (string.Equals(info.Name, newName, StringComparison.Ordinal)) return false;
4952
info.Name = newName;

0 commit comments

Comments
 (0)