ReadOnlySpanParamExtensions Class

Provides the checks of a chain that starts with Param.Check.

public static class ReadOnlySpanParamExtensions

Remarks

A check throws an exception if the value of the parameter is not valid. Otherwise, it returns a ReadOnlySpanParam<T>, so that another check can follow.

Every check takes an optional message for the exception it throws. The message is a composite format string, as the remarks of ParamExtensions describe it. A span cannot be converted to an object, so the format item {1} is the text of the span, as its ReadOnlySpan<T>.ToString method returns it. The text of a span of characters holds the characters. The text of any other span holds the name of its type and its length.

Methods

NameDescription
ReadOnlySpanParam<T>.Checked(ReadOnlySpanPredicate<T>, string?)Throws an ArgumentException if the value of a read-only span parameter does not satisfy a condition.
ReadOnlySpanParam<T>.Empty(string?)Throws an ArgumentException if the value of a read-only span parameter is not empty.
ReadOnlySpanParam<T>.HasSizeEqualTo(int, string?)Throws an ArgumentException if the value of a read-only span parameter does not have a specified length.
ReadOnlySpanParam<T>.HasSizeEqualTo(ReadOnlySpan<T>, string?)Throws an ArgumentException if the value of a read-only span parameter does not have the same length as a specified read-only span.
ReadOnlySpanParam<T>.HasSizeGreaterThan(int, string?)Throws an ArgumentException if the length of the value of a read-only span parameter is not greater than a specified value.
ReadOnlySpanParam<T>.HasSizeGreaterThanOrEqualTo(int, string?)Throws an ArgumentException if the length of the value of a read-only span parameter is less than a specified value.
ReadOnlySpanParam<T>.HasSizeLessThan(int, string?)Throws an ArgumentException if the length of the value of a read-only span parameter is not less than a specified value.
ReadOnlySpanParam<T>.HasSizeLessThanOrEqualTo(int, string?)Throws an ArgumentException if the length of the value of a read-only span parameter is greater than a specified value.
ReadOnlySpanParam<T>.HasSizeLessThanOrEqualTo(ReadOnlySpan<T>, string?)Throws an ArgumentException if the value of a read-only span parameter is longer than a specified read-only span.
ReadOnlySpanParam<T>.HasSizeNotEqualTo(int, string?)Throws an ArgumentException if the value of a read-only span parameter has a specified length.
ReadOnlySpanParam<T>.NotEmpty(string?)Throws an ArgumentException if the value of a read-only span parameter is empty.
ReadOnlySpanParam<char>.NotWhiteSpace(string?)Throws an ArgumentException if the value of a parameter that is a span of characters is empty, or consists only of white-space characters.
ReadOnlySpanParam<char>.WhiteSpace(string?)Throws an ArgumentException if the value of a parameter that is a span of characters holds a character that is not a white-space character.

ReadOnlySpanParam<T>.Checked(ReadOnlySpanPredicate<T>, string?)

Throws an ArgumentException if the value of a read-only span parameter does not satisfy a condition.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> Checked(ReadOnlySpanPredicate<T> predicate, string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
predicate ReadOnlySpanPredicate<T>
A function to test the value for a condition.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, and {1} is its text.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentNullException
predicate is null.
ArgumentException
predicate returns false for the value of this.

ReadOnlySpanParam<T>.Empty(string?)

Throws an ArgumentException if the value of a read-only span parameter is not empty.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> Empty(string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, and {2} is the length of the value.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The value of this holds at least one item.

ReadOnlySpanParam<T>.HasSizeEqualTo overloads

ReadOnlySpanParam<T>.HasSizeEqualTo(int, string?)

Throws an ArgumentException if the value of a read-only span parameter does not have a specified length.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeEqualTo(int size, string? message = null)
}
Type parameters
T
The type of the items of the read-only span.
Parameters
this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length that the value must have.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.
Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions
ArgumentException
The length of the value of this is not equal to size.

ReadOnlySpanParam<T>.HasSizeEqualTo(ReadOnlySpan<T>, string?)

Throws an ArgumentException if the value of a read-only span parameter does not have the same length as a specified read-only span.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeEqualTo(ReadOnlySpan<T> other, string? message = null)
}
Type parameters
T
The type of the items of the read-only span.
Parameters
this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
other ReadOnlySpan<T>
The read-only span whose length the value must have.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is the length of other, and {3} is the length of the value.
Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions
ArgumentException
The length of the value of this is not equal to the length of other.

ReadOnlySpanParam<T>.HasSizeGreaterThan(int, string?)

Throws an ArgumentException if the length of the value of a read-only span parameter is not greater than a specified value.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeGreaterThan(int size, string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length to compare with.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The length of the value of this is less than or equal to size.

ReadOnlySpanParam<T>.HasSizeGreaterThanOrEqualTo(int, string?)

Throws an ArgumentException if the length of the value of a read-only span parameter is less than a specified value.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeGreaterThanOrEqualTo(int size, string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length to compare with.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The length of the value of this is less than size.

ReadOnlySpanParam<T>.HasSizeLessThan(int, string?)

Throws an ArgumentException if the length of the value of a read-only span parameter is not less than a specified value.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeLessThan(int size, string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length to compare with.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The length of the value of this is greater than or equal to size.

ReadOnlySpanParam<T>.HasSizeLessThanOrEqualTo overloads

ReadOnlySpanParam<T>.HasSizeLessThanOrEqualTo(int, string?)

Throws an ArgumentException if the length of the value of a read-only span parameter is greater than a specified value.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeLessThanOrEqualTo(int size, string? message = null)
}
Type parameters
T
The type of the items of the read-only span.
Parameters
this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length to compare with.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.
Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions
ArgumentException
The length of the value of this is greater than size.

ReadOnlySpanParam<T>.HasSizeLessThanOrEqualTo(ReadOnlySpan<T>, string?)

Throws an ArgumentException if the value of a read-only span parameter is longer than a specified read-only span.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeLessThanOrEqualTo(ReadOnlySpan<T> other, string? message = null)
}
Type parameters
T
The type of the items of the read-only span.
Parameters
this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
other ReadOnlySpan<T>
The read-only span whose length to compare with.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is the length of other, and {3} is the length of the value.
Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions
ArgumentException
The length of the value of this is greater than the length of other.

ReadOnlySpanParam<T>.HasSizeNotEqualTo(int, string?)

Throws an ArgumentException if the value of a read-only span parameter has a specified length.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> HasSizeNotEqualTo(int size, string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
size int
The length that the value must not have.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, {1} is its text, {2} is size, and {3} is the length of the value.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The length of the value of this is equal to size.

ReadOnlySpanParam<T>.NotEmpty(string?)

Throws an ArgumentException if the value of a read-only span parameter is empty.

extension<T>(ReadOnlySpanParam<T> @this)
{
    public ReadOnlySpanParam<T> NotEmpty(string? message = null)
}

Type parameters

T
The type of the items of the read-only span.

Parameters

this ReadOnlySpanParam<T>
The ReadOnlySpanParam<T> that holds the read-only span to check.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, and {1} is its text.

Returns

ReadOnlySpanParam<T> this, for the next check of the chain.

Exceptions

ArgumentException
The value of this holds no item.

ReadOnlySpanParam<char>.NotWhiteSpace(string?)

Throws an ArgumentException if the value of a parameter that is a span of characters is empty, or consists only of white-space characters.

extension(ReadOnlySpanParam<char> @this)
{
    public ReadOnlySpanParam<char> NotWhiteSpace(string? message = null)
}

Parameters

this ReadOnlySpanParam<char>
The ReadOnlySpanParam<T> that holds the span of characters to check.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, and {1} is its text.

Returns

ReadOnlySpanParam<char> this, for the next check of the chain.

Exceptions

ArgumentException
The value of this is empty, or consists only of white-space characters.

ReadOnlySpanParam<char>.WhiteSpace(string?)

Throws an ArgumentException if the value of a parameter that is a span of characters holds a character that is not a white-space character.

extension(ReadOnlySpanParam<char> @this)
{
    public ReadOnlySpanParam<char> WhiteSpace(string? message = null)
}

Parameters

this ReadOnlySpanParam<char>
The ReadOnlySpanParam<T> that holds the span of characters to check.
message string?
A composite format string for the message of the exception, or null to use the default message. The format item {0} is the name of the parameter, and {1} is its text.

Returns

ReadOnlySpanParam<char> this, for the next check of the chain.

Exceptions

ArgumentException
The value of this holds at least one character that is not a white-space character.

Remarks

The check passes if the value is empty, or consists only of white-space characters.