Skip to content

Commit 6547cc1

Browse files
committed
Replaced NodeUuid with Guid.
1 parent 82b9db3 commit 6547cc1

File tree

6 files changed

+22
-232
lines changed

6 files changed

+22
-232
lines changed

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

Lines changed: 10 additions & 4 deletions
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 System.IO;
@@ -104,7 +104,7 @@ public void Load(Stream input, ILogger logger)
104104
{
105105
var node = new ClassNode(false)
106106
{
107-
Uuid = NodeUuid.FromBase64String(element.Attribute(XmlUuidAttribute)?.Value, true),
107+
Uuid = ParseUuid(element.Attribute(XmlUuidAttribute)?.Value),
108108
Name = element.Attribute(XmlNameAttribute)?.Value ?? string.Empty,
109109
Comment = element.Attribute(XmlCommentAttribute)?.Value ?? string.Empty,
110110
AddressFormula = element.Attribute(XmlAddressAttribute)?.Value ?? string.Empty
@@ -173,7 +173,7 @@ BaseNode CreateNode()
173173
{
174174
ClassNode GetClassNodeFromElementReference()
175175
{
176-
var reference = NodeUuid.FromBase64String(element.Attribute(XmlReferenceAttribute)?.Value, false);
176+
var reference = ParseUuid(element.Attribute(XmlReferenceAttribute)?.Value);
177177
if (!project.ContainsClass(reference))
178178
{
179179
logger.Log(LogLevel.Error, $"Skipping node with unknown reference: {reference}");
@@ -286,7 +286,7 @@ ClassNode GetClassNodeFromElementReference()
286286
{
287287
functionNode.Signature = element.Attribute(XmlSignatureAttribute)?.Value ?? string.Empty;
288288

289-
var reference = NodeUuid.FromBase64String(element.Attribute(XmlReferenceAttribute)?.Value, false);
289+
var reference = ParseUuid(element.Attribute(XmlReferenceAttribute)?.Value);
290290
if (project.ContainsClass(reference))
291291
{
292292
functionNode.BelongsToClass = project.GetClassByUuid(reference);
@@ -306,6 +306,12 @@ ClassNode GetClassNodeFromElementReference()
306306
return node;
307307
}
308308

309+
private static Guid ParseUuid(string raw) => raw == null
310+
? throw new ArgumentNullException()
311+
: raw.Length == 24
312+
? new Guid(Convert.FromBase64String(raw))
313+
: Guid.Parse(raw);
314+
309315
public static Tuple<List<ClassNode>, List<BaseNode>> DeserializeNodesFromStream(Stream input, ReClassNetProject templateProject, ILogger logger)
310316
{
311317
Contract.Requires(input != null);

ReClass.NET/DataExchange/ReClass/ReClassNetFile.Write.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics.Contracts;
34
using System.IO;
45
using System.IO.Compression;
@@ -67,7 +68,7 @@ private static IEnumerable<XElement> CreateClassElements(IEnumerable<ClassNode>
6768

6869
return classes.Select(c => new XElement(
6970
XmlClassElement,
70-
new XAttribute(XmlUuidAttribute, c.Uuid.ToBase64String()),
71+
new XAttribute(XmlUuidAttribute, c.Uuid),
7172
new XAttribute(XmlNameAttribute, c.Name ?? string.Empty),
7273
new XAttribute(XmlCommentAttribute, c.Comment ?? string.Empty),
7374
new XAttribute(XmlAddressAttribute, c.AddressFormula ?? string.Empty),
@@ -118,7 +119,7 @@ XElement CreateElement()
118119
{
119120
if (node is BaseClassWrapperNode classWrapperNode)
120121
{
121-
element.SetAttributeValue(XmlReferenceAttribute, ((ClassNode)classWrapperNode.InnerNode).Uuid.ToBase64String());
122+
element.SetAttributeValue(XmlReferenceAttribute, ((ClassNode)classWrapperNode.InnerNode).Uuid);
122123
}
123124
else if (wrapperNode.InnerNode != null)
124125
{
@@ -160,8 +161,8 @@ XElement CreateElement()
160161
}
161162
case FunctionNode functionNode:
162163
{
163-
var uuid = functionNode.BelongsToClass == null ? NodeUuid.Zero : functionNode.BelongsToClass.Uuid;
164-
element.SetAttributeValue(XmlReferenceAttribute, uuid.ToBase64String());
164+
var uuid = functionNode.BelongsToClass?.Uuid ?? Guid.Empty;
165+
element.SetAttributeValue(XmlReferenceAttribute, uuid);
165166
element.SetAttributeValue(XmlSignatureAttribute, functionNode.Signature);
166167
break;
167168
}

ReClass.NET/Nodes/ClassNode.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,7 @@ public class ClassNode : BaseContainerNode
2525

2626
protected override bool ShouldCompensateSizeChanges => true;
2727

28-
private NodeUuid uuid;
29-
public NodeUuid Uuid
30-
{
31-
get => uuid;
32-
set
33-
{
34-
Contract.Requires(value != null);
35-
36-
uuid = value;
37-
}
38-
}
28+
public Guid Uuid { get; set; }
3929

4030
public string AddressFormula { get; set; } = DefaultAddressFormula;
4131

@@ -47,7 +37,7 @@ internal ClassNode(bool notifyClassCreated)
4737

4838
LevelsOpen.DefaultValue = true;
4939

50-
Uuid = new NodeUuid(true);
40+
Uuid = Guid.NewGuid();
5141

5242
if (notifyClassCreated)
5343
{

ReClass.NET/Nodes/NodeUuid.cs

Lines changed: 0 additions & 206 deletions
This file was deleted.

ReClass.NET/Project/ReClassNetProject.cs

Lines changed: 3 additions & 3 deletions
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 System.Linq;
@@ -59,14 +59,14 @@ public void AddClass(ClassNode node)
5959
ClassAdded?.Invoke(node);
6060
}
6161

62-
public bool ContainsClass(NodeUuid uuid)
62+
public bool ContainsClass(Guid uuid)
6363
{
6464
Contract.Requires(uuid != null);
6565

6666
return classes.Any(c => c.Uuid.Equals(uuid));
6767
}
6868

69-
public ClassNode GetClassByUuid(NodeUuid uuid)
69+
public ClassNode GetClassByUuid(Guid uuid)
7070
{
7171
Contract.Requires(uuid != null);
7272

ReClass.NET/ReClass.NET.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -290,7 +290,6 @@
290290
<Compile Include="Nodes\EnumNode.cs" />
291291
<Compile Include="Nodes\FunctionNode.cs" />
292292
<Compile Include="Nodes\NIntNode.cs" />
293-
<Compile Include="Nodes\NodeUuid.cs" />
294293
<Compile Include="Nodes\PointerNode.cs" />
295294
<Compile Include="Nodes\NUIntNode.cs" />
296295
<Compile Include="Nodes\UnionNode.cs" />

0 commit comments

Comments
 (0)