Skip to content

Commit b1de782

Browse files
committed
Fix BaseNode.Initialize not getting called.
1 parent 82078e4 commit b1de782

File tree

6 files changed

+65
-45
lines changed

6 files changed

+65
-45
lines changed

ReClass.NET/DataExchange/ReClass/ReClass2007File.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private static IEnumerable<BaseNode> ReadNodeRows(IEnumerable<DataRow> rows, Cla
136136
continue;
137137
}
138138

139-
var node = BaseNode.CreateInstanceFromType(nodeType);
139+
var node = BaseNode.CreateInstanceFromType(nodeType, false);
140140
if (node == null)
141141
{
142142
logger.Log(LogLevel.Error, $"Could not create node of type: {nodeType}");

ReClass.NET/DataExchange/ReClass/ReClassFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private IEnumerable<BaseNode> ReadNodeElements(IEnumerable<XElement> elements, C
153153
continue;
154154
}
155155

156-
var node = BaseNode.CreateInstanceFromType(nodeType);
156+
var node = BaseNode.CreateInstanceFromType(nodeType, false);
157157
if (node == null)
158158
{
159159
logger.Log(LogLevel.Error, $"Could not create node of type: {nodeType}");

ReClass.NET/DataExchange/ReClass/ReClassNetFile.Read.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private BaseNode CreateNodeFromElement(XElement element, BaseNode parent, ILogge
122122
return null;
123123
}
124124

125-
var node = BaseNode.CreateInstanceFromType(nodeType);
125+
var node = BaseNode.CreateInstanceFromType(nodeType, false);
126126
if (node == null)
127127
{
128128
logger.Log(LogLevel.Error, $"Could not create node of type: {nodeType}");

ReClass.NET/DataExchange/ReClass/ReClassQtFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private IEnumerable<BaseNode> ReadNodeElements(IEnumerable<XElement> elements, C
135135
continue;
136136
}
137137

138-
var node = BaseNode.CreateInstanceFromType(nodeType);
138+
var node = BaseNode.CreateInstanceFromType(nodeType, false);
139139
if (node == null)
140140
{
141141
logger.Log(LogLevel.Error, $"Could not create node of type: {nodeType}");

ReClass.NET/Nodes/BaseNode.cs

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,30 @@ private void ObjectInvariants()
6666
Contract.Invariant(LevelsOpen != null);
6767
}
6868

69+
/// <summary>
70+
/// Creates an instance of the specific node type.
71+
/// </summary>
72+
/// <param name="nodeType">The <see cref="Type"/> of the node.</param>
73+
/// <returns>An instance of the node type or null if the type is not a valid node type.</returns>
6974
public static BaseNode CreateInstanceFromType(Type nodeType)
7075
{
71-
return Activator.CreateInstance(nodeType) as BaseNode;
76+
return CreateInstanceFromType(nodeType, true);
77+
}
78+
79+
/// <summary>
80+
/// Creates an instance of the specific node type.
81+
/// </summary>
82+
/// <param name="nodeType">The <see cref="Type"/> of the node.</param>
83+
/// <param name="callInitialize">If true <see cref="Intialize"/> gets called for the new node.</param>
84+
/// <returns>An instance of the node type or null if the type is not a valid node type.</returns>
85+
public static BaseNode CreateInstanceFromType(Type nodeType, bool callInitialize)
86+
{
87+
var node = Activator.CreateInstance(nodeType) as BaseNode;
88+
if (callInitialize)
89+
{
90+
node?.Intialize();
91+
}
92+
return node;
7293
}
7394

7495
/// <summary>Constructor which sets a unique <see cref="Name"/>.</summary>
@@ -85,6 +106,44 @@ protected BaseNode()
85106

86107
public abstract void GetUserInterfaceInfo(out string name, out Image icon);
87108

109+
public virtual bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
110+
{
111+
Contract.Requires(spot != null);
112+
Contract.Requires(memory != null);
113+
114+
address = IntPtr.Zero;
115+
116+
return false;
117+
}
118+
119+
/// <summary>Gets informations about this node to show in a tool tip.</summary>
120+
/// <param name="spot">The spot.</param>
121+
/// <param name="memory">The process memory.</param>
122+
/// <returns>The information to show in a tool tip or null if no information should be shown.</returns>
123+
public virtual string GetToolTipText(HotSpot spot, MemoryBuffer memory)
124+
{
125+
Contract.Requires(spot != null);
126+
Contract.Requires(memory != null);
127+
128+
return null;
129+
}
130+
131+
/// <summary>Called when the node was created. Does not get called after loading a project.</summary>
132+
public virtual void Intialize()
133+
{
134+
135+
}
136+
137+
/// <summary>Initializes this object from the given node. It copies the name and the comment.</summary>
138+
/// <param name="node">The node to copy from.</param>
139+
public virtual void CopyFromNode(BaseNode node)
140+
{
141+
Contract.Requires(node != null);
142+
143+
Name = node.Name;
144+
Comment = node.Comment;
145+
}
146+
88147
/// <summary>
89148
/// Gets the parent class of the node.
90149
/// </summary>
@@ -139,45 +198,6 @@ public virtual void ClearSelection()
139198
IsSelected = false;
140199
}
141200

142-
/// <summary>Initializes this object from the given node. It copies the name and the comment.</summary>
143-
/// <param name="node">The node to copy from.</param>
144-
public virtual void CopyFromNode(BaseNode node)
145-
{
146-
Contract.Requires(node != null);
147-
148-
Name = node.Name;
149-
Comment = node.Comment;
150-
}
151-
152-
153-
/// <summary>Called when the node was created. Does not get called after loading a project.</summary>
154-
public virtual void Intialize()
155-
{
156-
157-
}
158-
159-
public virtual bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
160-
{
161-
Contract.Requires(spot != null);
162-
Contract.Requires(memory != null);
163-
164-
address = IntPtr.Zero;
165-
166-
return false;
167-
}
168-
169-
/// <summary>Gets informations about this node to show in a tool tip.</summary>
170-
/// <param name="spot">The spot.</param>
171-
/// <param name="memory">The process memory.</param>
172-
/// <returns>The information to show in a tool tip or null if no information should be shown.</returns>
173-
public virtual string GetToolTipText(HotSpot spot, MemoryBuffer memory)
174-
{
175-
Contract.Requires(spot != null);
176-
Contract.Requires(memory != null);
177-
178-
return null;
179-
}
180-
181201
/// <summary>Draws the node.</summary>
182202
/// <param name="view">The view information.</param>
183203
/// <param name="x">The x coordinate.</param>

ReClass.NET/UI/NodeTypesBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static void GetNodeInfoFromType(Type nodeType, out string label, out Ima
148148
{
149149
Contract.Requires(nodeType != null);
150150

151-
var node = BaseNode.CreateInstanceFromType(nodeType);
151+
var node = BaseNode.CreateInstanceFromType(nodeType, false);
152152
if (node == null)
153153
{
154154
throw new InvalidOperationException($"'{nodeType}' is not a valid node type.");

0 commit comments

Comments
 (0)