SpanParamExtensions Class

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

public static class SpanParamExtensions

Remarks

A check throws an exception if the value of the parameter is not valid. Otherwise, it returns a SpanParam<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 Span<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
SpanParam<T>.Checked(ReadOnlySpanPredicate<T>, string?)Throws an ArgumentException if the value of a span parameter does not satisfy a condition.
SpanParam<T>.Empty(string?)Throws an ArgumentException if the value of a span parameter is not empty.
SpanParam<T>.HasSizeEqualTo(int, string?)Throws an ArgumentException if the value of a span parameter does not have a specified length.
SpanParam<T>.HasSizeEqualTo(ReadOnlySpan<T>, string?)Throws an ArgumentException if the value of a span parameter does not have the same length as a specified read-only span.
SpanParam<T>.HasSizeGreaterThan(int, string?)Throws an ArgumentException if the length of the value of a span parameter is not greater than a specified value.
SpanParam<T>.HasSizeGreaterThanOrEqualTo(int, string?)Throws an ArgumentException if the length of the value of a span parameter is less than a specified value.
SpanParam<T>.HasSizeLessThan(int, string?)Throws an ArgumentException if the length of the value of a span parameter is not less than a specified value.
SpanParam<T>.HasSizeLessThanOrEqualTo(int, string?)Throws an ArgumentException if the length of the value of a span parameter is greater than a specified value.
SpanParam<T>.HasSizeLessThanOrEqualTo(ReadOnlySpan<T>, string?)Throws an ArgumentException if the value of a span parameter is longer than a specified read-only span.
SpanParam<T>.HasSizeNotEqualTo(int, string?)Throws an ArgumentException if the value of a span parameter has a specified length.
SpanParam<T>.NotEmpty(string?)Throws an ArgumentException if the value of a span parameter is empty.
SpanParam<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.
SpanParam<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.

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

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

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

Exceptions

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

SpanParam<T>.Empty(string?)

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

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

Exceptions

ArgumentException
The value of this holds at least one item.

SpanParam<T>.HasSizeEqualTo overloads

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

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

extension<T>(SpanParam<T> @this)
{
    public SpanParam<T> HasSizeEqualTo(int size, string? message = null)
}
Type parameters
T
The type of the items of the span.
Parameters
this SpanParam<T>
The SpanParam<T> that holds the 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

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

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

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

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

extension<T>(SpanParam<T> @this)
{
    public SpanParam<T> HasSizeEqualTo(ReadOnlySpan<T> other, string? message = null)
}
Type parameters
T
The type of the items of the span.
Parameters
this SpanParam<T>
The SpanParam<T> that holds the 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

SpanParam<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.

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

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

SpanParam<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.

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

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

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

Exceptions

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

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

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

SpanParam<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.

SpanParam<T>.HasSizeLessThanOrEqualTo overloads

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

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

extension<T>(SpanParam<T> @this)
{
    public SpanParam<T> HasSizeLessThanOrEqualTo(int size, string? message = null)
}
Type parameters
T
The type of the items of the span.
Parameters
this SpanParam<T>
The SpanParam<T> that holds the 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

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

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

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

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

extension<T>(SpanParam<T> @this)
{
    public SpanParam<T> HasSizeLessThanOrEqualTo(ReadOnlySpan<T> other, string? message = null)
}
Type parameters
T
The type of the items of the span.
Parameters
this SpanParam<T>
The SpanParam<T> that holds the 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

SpanParam<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.

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

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

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

Exceptions

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

SpanParam<T>.NotEmpty(string?)

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

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

Type parameters

T
The type of the items of the span.

Parameters

this SpanParam<T>
The SpanParam<T> that holds the 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

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

Exceptions

ArgumentException
The value of this holds no item.

SpanParam<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(SpanParam<char> @this)
{
    public SpanParam<char> NotWhiteSpace(string? message = null)
}

Parameters

this SpanParam<char>
The SpanParam<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

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

Exceptions

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

SpanParam<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(SpanParam<char> @this)
{
    public SpanParam<char> WhiteSpace(string? message = null)
}

Parameters

this SpanParam<char>
The SpanParam<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

SpanParam<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.