public static ReadOnlySpan <T> PickRandom <T>(this ReadOnlySpan <T> span) { span = span.ArgumentNotEmpty(); var index = RandomNumberGenerator.GetInt32(0, span.Length - 1); return(span[index..]);
public static string BytesToString(this ReadOnlySpan <byte> array) { array = array.ArgumentNotEmpty(nameof(array)); var sb = new StringBuilder(array.Length); for (var byteCount = 0; byteCount < array.Length; byteCount++) { _ = sb.Append(array[byteCount].ToString("x2", CultureInfo.InvariantCulture)); } return(sb.ToString()); }
public void ArgumentNotEmptyReadOnlySpanTest01() { try { ReadOnlySpan <PersonProper> people = RandomData.GeneratePersonRefCollection <PersonProper>(10).ToArray(); people.ArgumentNotEmpty(); } catch { Assert.Fail(); } }
public void ArgumentNotNullReadOnlySpanTest() { var testPeople = new ReadOnlySpan <PersonProper>(RandomData.GeneratePersonRefCollection <PersonProper>(10).ToArray()); try { testPeople.ArgumentNotEmpty(); } catch { Assert.Fail(); } _ = Assert.ThrowsException <ArgumentNullException>(() => ReadOnlySpan <PersonProper> .Empty.ArgumentNotEmpty()); }
public void ArgumentNotEmptyReadOnlySpanTest02() { try { var people = new ReadOnlySpan <PersonProper>(); people.ArgumentNotEmpty(); Assert.Fail(); } catch { Assert.IsTrue(true); } }