Skip to content

Commit a55ebc4

Browse files
committed
Improved type checks.
1 parent 85a81dd commit a55ebc4

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

ReClass.NET/Nodes/BaseContainerNode.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
44
using ReClassNET.Extensions;
@@ -18,6 +18,13 @@ private void ObjectInvariants()
1818
/// <summary>The child nodes of the node.</summary>
1919
public IEnumerable<BaseNode> Nodes => nodes;
2020

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+
2128
/// <summary>Calculates the offset of every child node.</summary>
2229
public void UpdateOffsets()
2330
{

ReClass.NET/Nodes/BaseWrapperArrayNode.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ public abstract class BaseWrapperArrayNode : BaseWrapperNode
1616

1717
public override bool CanChangeInnerNodeTo(BaseNode node)
1818
{
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+
}
2026

21-
return node != null;
27+
return true;
2228
}
2329

2430
protected Size Draw(ViewInfo view, int x, int y, string type)

ReClass.NET/Nodes/ClassNode.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
7979
throw new InvalidOperationException($"The '{nameof(ClassNode)}' node should not be accessible from the ui.");
8080
}
8181

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+
8295
public override void Intialize()
8396
{
8497
AddBytes(IntPtr.Size);

ReClass.NET/Nodes/PointerNode.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
2626

2727
public override bool CanChangeInnerNodeTo(BaseNode node)
2828
{
29+
switch (node)
30+
{
31+
case ClassNode _:
32+
case VMethodNode _:
33+
return false;
34+
}
35+
2936
return true;
3037
}
3138

ReClass.NET/Nodes/VTableNode.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
1919
icon = Properties.Resources.B16x16_Button_VTable;
2020
}
2121

22+
public override bool CanHandleChildNode(BaseNode node)
23+
{
24+
return node is VMethodNode;
25+
}
26+
2227
public override void Intialize()
2328
{
2429
AddBytes(10 * IntPtr.Size);

0 commit comments

Comments
 (0)