|
1 | 1 | using System; |
| 2 | +using System.Diagnostics; |
2 | 3 | using System.Globalization; |
3 | 4 | using Confuser.Core; |
4 | 5 | using Confuser.Renamer.BAML; |
5 | 6 | using dnlib.DotNet; |
6 | 7 |
|
7 | 8 | namespace Confuser.Renamer.References { |
8 | 9 | internal class BAMLPathTypeReference : INameReference<TypeDef> { |
9 | | - private SourceValueInfo? propertyInfo; |
10 | | - private IndexerParamInfo? indexerInfo; |
| 10 | + PropertyPathPartUpdater? PropertyInfo { get; } |
| 11 | + PropertyPathIndexUpdater? IndexerInfo { get; } |
11 | 12 | private readonly TypeSig sig; |
12 | 13 | private readonly BAMLAnalyzer.XmlNsContext xmlnsCtx; |
13 | 14 |
|
14 | 15 | private BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig) { |
15 | | - if (xmlnsCtx == null) throw new ArgumentNullException(nameof(xmlnsCtx)); |
16 | | - if (sig == null) throw new ArgumentNullException(nameof(sig)); |
17 | | - |
18 | | - this.xmlnsCtx = xmlnsCtx; |
19 | | - this.sig = sig; |
| 16 | + this.xmlnsCtx = xmlnsCtx ?? throw new ArgumentNullException(nameof(xmlnsCtx)); |
| 17 | + this.sig = sig ?? throw new ArgumentNullException(nameof(sig)); |
20 | 18 | } |
21 | 19 |
|
22 | | - public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, IndexerParamInfo indexerInfo) : this(xmlnsCtx, sig) => |
23 | | - this.indexerInfo = indexerInfo; |
| 20 | + public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathIndexUpdater indexerInfo) : this(xmlnsCtx, sig) => |
| 21 | + IndexerInfo = indexerInfo; |
24 | 22 |
|
25 | | - public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, SourceValueInfo propertyInfo) : this(xmlnsCtx, sig) => |
26 | | - this.propertyInfo = propertyInfo; |
| 23 | + public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathPartUpdater propertyInfo) : this(xmlnsCtx, sig) => |
| 24 | + PropertyInfo = propertyInfo; |
27 | 25 |
|
28 | 26 | public bool UpdateNameReference(ConfuserContext context, INameService service) { |
29 | 27 | string name = sig.ReflectionName; |
30 | 28 | string prefix = xmlnsCtx.GetPrefix(sig.ReflectionNamespace, sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module.Assembly); |
31 | 29 | if (!string.IsNullOrEmpty(prefix)) |
32 | 30 | name = prefix + ":" + name; |
33 | 31 |
|
34 | | - if (indexerInfo != null) { |
35 | | - var info = indexerInfo.Value; |
36 | | - if (string.Equals(info.parenString, name, StringComparison.Ordinal)) return false; |
37 | | - info.parenString = name; |
38 | | - indexerInfo = info; |
| 32 | + if (IndexerInfo != null) { |
| 33 | + var info = IndexerInfo.Value; |
| 34 | + if (string.Equals(info.ParenString, name, StringComparison.Ordinal)) return false; |
| 35 | + info.ParenString = name; |
39 | 36 | } |
40 | 37 | else { |
41 | | - var info = propertyInfo.Value; |
| 38 | + Debug.Assert(PropertyInfo != null, nameof(PropertyInfo) + " != null"); |
| 39 | + var info = PropertyInfo.Value; |
42 | 40 | var propertyName = info.GetPropertyName(); |
43 | 41 | var newName = string.Format(CultureInfo.InvariantCulture, "({0}.{1})", name, propertyName); |
44 | | - if (string.Equals(info.name, newName, StringComparison.Ordinal)) return false; |
45 | | - info.name = newName; |
46 | | - propertyInfo = info; |
| 42 | + if (string.Equals(info.Name, newName, StringComparison.Ordinal)) return false; |
| 43 | + info.Name = newName; |
47 | 44 | } |
48 | 45 | return true; |
49 | 46 | } |
|
0 commit comments