Skip to content

Commit 488ab3b

Browse files
committed
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary into develop
***NO_CI***
2 parents e37e4b8 + 0e0f7be commit 488ab3b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Tests/NFUnitTestSystemLib/UnitTestGuid.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,29 @@ public void Ctor_UInt_UShort_UShort_Byte_Byte_Byte_Byte_Byte_Byte_Byte_Byte()
419419
[TestMethod]
420420
public void NewGuid()
421421
{
422+
// generate a new Guid
422423
Guid guid1 = Guid.NewGuid();
423424

425+
OutputHelper.WriteLine($"Guid1: {guid1}");
426+
427+
// check that the guid is not empty
424428
Assert.AreNotEqual(Guid.Empty, guid1);
429+
// check version 4
425430
Assert.IsTrue((guid1.ToByteArray()[7] & 0xF0) == 0x40);
431+
// check variant
432+
Assert.IsTrue((guid1.ToByteArray()[8] & 0xC0) == 0x80);
426433

434+
// go for another one
427435
Guid guid2 = Guid.NewGuid();
428436

437+
OutputHelper.WriteLine($"Guid2: {guid2}");
438+
439+
// check that the guid is not empty
429440
Assert.AreNotEqual(guid1, guid2);
441+
// check version 4
430442
Assert.IsTrue((guid2.ToByteArray()[7] & 0xF0) == 0x40);
443+
// check variant
444+
Assert.IsTrue((guid2.ToByteArray()[8] & 0xC0) == 0x80);
431445
}
432446

433447
[TestMethod]

nanoFramework.CoreLibrary/System/Guid.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ public int CompareTo(object value)
190190
/// Returns a 16-element byte array that contains the value of this instance.
191191
/// </summary>
192192
/// <returns>A 16-element byte array.</returns>
193+
/// <remarks>
194+
/// <para>
195+
/// You can use the byte array returned by this method to round-trip a Guid value by calling the <see cref="Guid(byte[])"/> constructor.
196+
/// </para>
197+
/// <para>
198+
/// Note that the order of bytes in the returned byte array is different from the string representation of a Guid value.
199+
/// The order of the beginning four-byte group and the next two two-byte groups is reversed, whereas the order of the last two-byte group and the closing six-byte group is the same.
200+
/// </para>
201+
/// </remarks>
193202
public byte[] ToByteArray()
194203
{
195204
byte[] buffer = new byte[16];

0 commit comments

Comments
 (0)