Beispiel #1
0
        public static ReadOnlySpan <T> PickRandom <T>(this ReadOnlySpan <T> span)
        {
            span = span.ArgumentNotEmpty();

            var index = RandomNumberGenerator.GetInt32(0, span.Length - 1);

            return(span[index..]);
Beispiel #2
0
        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());
        }
Beispiel #3
0
        public void ArgumentNotEmptyReadOnlySpanTest01()
        {
            try
            {
                ReadOnlySpan <PersonProper> people = RandomData.GeneratePersonRefCollection <PersonProper>(10).ToArray();

                people.ArgumentNotEmpty();
            }
            catch
            {
                Assert.Fail();
            }
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
        public void ArgumentNotEmptyReadOnlySpanTest02()
        {
            try
            {
                var people = new ReadOnlySpan <PersonProper>();

                people.ArgumentNotEmpty();

                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }