Extensions: ArraySegment.ToHexString for convenience

This commit is contained in:
vis2k 2022-09-25 13:17:02 +07:00
parent 9525a4649d
commit 27398721a2
2 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,9 @@ namespace Mirror
{
public static class Extensions
{
public static string ToHexString(this ArraySegment<byte> segment) =>
BitConverter.ToString(segment.Array, segment.Offset, segment.Count);
// string.GetHashCode is not guaranteed to be the same on all machines, but
// we need one that is the same on all machines. simple and stupid:
public static int GetStableHashCode(this string text)

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
@ -17,10 +18,17 @@ public void GetStableHashHode()
[Test]
public void CopyToList()
{
List<int> source = new List<int>{1, 2, 3};
List<int> source = new List<int> {1, 2, 3};
List<int> destination = new List<int>();
source.CopyTo(destination);
Assert.That(destination.SequenceEqual(source), Is.True);
}
[Test]
public void ArraySegment_ToHexString()
{
ArraySegment<byte> segment = new ArraySegment<byte>(new byte[] {0xAA, 0xBB, 0xCC});
Assert.That(segment.ToHexString(), Is.EqualTo("AA-BB-CC"));
}
}
}