|
1 | 1 | using System;
|
2 | 2 | using System.ComponentModel.Composition;
|
| 3 | +using System.Linq; |
3 | 4 | using dnlib.DotNet;
|
4 | 5 | using dnSpy.Contracts.App;
|
5 | 6 | using dnSpy.Contracts.Documents.Tabs;
|
@@ -48,13 +49,46 @@ public override void Execute(IMenuItemContext context)
|
48 | 49 | if (isConstructor)
|
49 | 50 | member.DeclaringType.Name = newName;
|
50 | 51 | else
|
| 52 | + { |
| 53 | + if (member is MethodDef method && (method.IsAbstract || method.IsVirtual)) |
| 54 | + { |
| 55 | + foreach(var t in method.Module.GetTypes().Where(x => HasBaseType(x, method.DeclaringType, false))) |
| 56 | + { |
| 57 | + var @override = t.FindMethod(method.Name, method.MethodSig); |
| 58 | + if (@override is { IsVirtual: true }) |
| 59 | + @override.Name = newName; |
| 60 | + } |
| 61 | + } |
| 62 | + |
51 | 63 | member.Name = newName;
|
| 64 | + } |
52 | 65 |
|
53 | 66 | var moduleDocNode = _documentTabService.DocumentTreeView.FindNode(member.Module)!;
|
54 | 67 | _documentTabService.DocumentTreeView.TreeView.RefreshAllNodes();
|
55 | 68 | _documentTabService.RefreshModifiedDocument(moduleDocNode.Document);
|
56 | 69 | }
|
57 | 70 |
|
| 71 | + /// <summary> |
| 72 | + /// Checks whether a type implements a specific base type. |
| 73 | + /// </summary> |
| 74 | + /// <param name="type">The type to check on.</param> |
| 75 | + /// <param name="baseType">The base type to check for.</param> |
| 76 | + /// <param name="implicit">Whether to check the type itself against the base type as well.</param> |
| 77 | + /// <returns>Whether the type implements a specific base type.</returns> |
| 78 | + private static bool HasBaseType(ITypeDefOrRef type, ITypeDefOrRef baseType, bool @implicit = true) |
| 79 | + { |
| 80 | + var bt = @implicit ? type : type.GetBaseType(); |
| 81 | + while (bt is not null) |
| 82 | + { |
| 83 | + if (bt.Equals(baseType)) |
| 84 | + return true; |
| 85 | + |
| 86 | + bt = bt.GetBaseType(); |
| 87 | + } |
| 88 | + |
| 89 | + return false; |
| 90 | + } |
| 91 | + |
58 | 92 | private static IMemberDef? GetMemberDef(IMenuItemContext context)
|
59 | 93 | {
|
60 | 94 | if (context.CreatorObject.Guid == new Guid(MenuConstants.GUIDOBJ_DOCUMENTVIEWERCONTROL_GUID))
|
|
0 commit comments