GeezerVison is showing github.com — Improved type checks. · ReClassNET/ReClass.NET@a55ebc4
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: ReClass.NET/Nodes/BaseContainerNode.cs +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics.Contracts; |
4 | 4 | using ReClassNET.Extensions; |
@@ -18,6 +18,13 @@ private void ObjectInvariants() |
18 | 18 | /// <summary>The child nodes of the node.</summary> |
19 | 19 | public IEnumerable<BaseNode> Nodes => nodes; |
20 | 20 |
|
| 21 | + /// <summary> |
| 22 | + /// Should be called before adding a child to test if the container can handle the node type. |
| 23 | + /// </summary> |
| 24 | + /// <param name="node">The new child node.</param> |
| 25 | + /// <returns>True if the container can handle the child node or false otherwise.</returns> |
| 26 | + public abstract bool CanHandleChildNode(BaseNode node); |
| 27 | + |
21 | 28 | /// <summary>Calculates the offset of every child node.</summary> |
22 | 29 | public void UpdateOffsets() |
23 | 30 | { |
|
Collapse file
Copy file name to clipboardExpand all lines: ReClass.NET/Nodes/BaseWrapperArrayNode.cs +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,9 +16,15 @@ public abstract class BaseWrapperArrayNode : BaseWrapperNode |
16 | 16 |
|
17 | 17 | public override bool CanChangeInnerNodeTo(BaseNode node) |
18 | 18 | { |
19 | | - // A null node (aka void) is not allowed for instances. |
| 19 | + switch (node) |
| 20 | + { |
| 21 | + case null: |
| 22 | + case ClassNode _: |
| 23 | + case VMethodNode _: |
| 24 | + return false; |
| 25 | + } |
20 | 26 |
|
21 | | - return node != null; |
| 27 | + return true; |
22 | 28 | } |
23 | 29 |
|
24 | 30 | protected Size Draw(ViewInfo view, int x, int y, string type) |
|
Collapse file
Copy file name to clipboardExpand all lines: ReClass.NET/Nodes/ClassNode.cs +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,6 +79,19 @@ public override void GetUserInterfaceInfo(out string name, out Image icon) |
79 | 79 | throw new InvalidOperationException($"The '{nameof(ClassNode)}' node should not be accessible from the ui."); |
80 | 80 | } |
81 | 81 |
|
| 82 | + public override bool CanHandleChildNode(BaseNode node) |
| 83 | + { |
| 84 | + switch (node) |
| 85 | + { |
| 86 | + case null: |
| 87 | + case ClassNode _: |
| 88 | + case VMethodNode _: |
| 89 | + return false; |
| 90 | + } |
| 91 | + |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
82 | 95 | public override void Intialize() |
83 | 96 | { |
84 | 97 | AddBytes(IntPtr.Size); |
|
Collapse file
Copy file name to clipboardExpand all lines: ReClass.NET/Nodes/PointerNode.cs +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,13 @@ public override void GetUserInterfaceInfo(out string name, out Image icon) |
26 | 26 |
|
27 | 27 | public override bool CanChangeInnerNodeTo(BaseNode node) |
28 | 28 | { |
| 29 | + switch (node) |
| 30 | + { |
| 31 | + case ClassNode _: |
| 32 | + case VMethodNode _: |
| 33 | + return false; |
| 34 | + } |
| 35 | + |
29 | 36 | return true; |
30 | 37 | } |
31 | 38 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: ReClass.NET/Nodes/VTableNode.cs +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,11 @@ public override void GetUserInterfaceInfo(out string name, out Image icon) |
19 | 19 | icon = Properties.Resources.B16x16_Button_VTable; |
20 | 20 | } |
21 | 21 |
|
| 22 | + public override bool CanHandleChildNode(BaseNode node) |
| 23 | + { |
| 24 | + return node is VMethodNode; |
| 25 | + } |
| 26 | + |
22 | 27 | public override void Intialize() |
23 | 28 | { |
24 | 29 | AddBytes(10 * IntPtr.Size); |
|