Skip to content

Commit ce5c6d8

Browse files
authored
Fix Guid constructor (#259)
***NO_CI***
1 parent 51be470 commit ce5c6d8

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Tests/NFUnitTestSystemLib/UnitTestInitLocalTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,24 @@ public void SystemType1_ArrayListToArrayForStruct_Test()
215215
// make sure boxing of struct value type (Guid) is handled properly
216216
// this test was a result of a bug found by a customer.
217217
Guid ret = new Guid();
218+
218219
ArrayList guidList = new ArrayList();
219220
guidList.Add(Guid.NewGuid());
220221
guidList.Add(Guid.NewGuid());
222+
221223
Guid[] guidArray = (Guid[])guidList.ToArray(typeof(Guid));
222224

225+
// Verify the array has the correct length
226+
Assert.AreEqual(2, guidArray.Length);
227+
228+
// Verify each element is not empty and matches the source list
229+
int i = 0;
223230
foreach (Guid g in guidArray)
224231
{
232+
Assert.IsFalse(Guid.Empty.Equals(g), "Guid should not be empty");
233+
Assert.AreEqual(guidList[i], g, "Guid should match the source ArrayList element");
225234
ret = g;
235+
i++;
226236
}
227237
}
228238

Tests/NFUnitTestTypes/UnitTestGuid.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public void Guid_TryParseGuidWithDashes_Valid()
9999
{
100100
var g1 = Guid.NewGuid();
101101
var str = g1.ToString();
102-
bool parsed = Guid.TryParseGuidWithDashes(str, out var g2);
102+
bool parsed = Guid.TryParse(str, out var g2);
103103
Assert.IsTrue(parsed);
104104
Assert.AreEqual(g1, g2);
105105
}
106106

107107
[TestMethod]
108108
public void Guid_TryParseGuidWithDashes_Invalid()
109109
{
110-
bool parsed = Guid.TryParseGuidWithDashes("invalid-guid", out var g2);
110+
bool parsed = Guid.TryParse("invalid-guid", out var g2);
111111
Assert.IsFalse(parsed);
112112
Assert.AreEqual(Guid.Empty, g2);
113113
}

nanoFramework.CoreLibrary/System/Guid.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ namespace System
1111
[Serializable]
1212
public struct Guid
1313
{
14-
private int[] _data;
14+
private int[] _data = new int[4];
1515

1616
/// <summary>
1717
/// A read-only instance of the Guid class which consists of all zeros.
1818
/// </summary>
1919
public static readonly Guid Empty = new Guid(new byte[16]);
2020

21-
public Guid()
22-
{
23-
// All zeros
24-
_data = new int[4];
25-
}
26-
2721
/// <summary>
2822
/// Initializes a new instance of the <see cref="Guid"/> structure by using the specified integers and bytes.
2923
/// </summary>

0 commit comments

Comments
 (0)