SpanParamExtensions Class
Provides the checks of a chain that starts with Param.Check.
public static class SpanParamExtensionsRemarks
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
| Name | Description |
|---|---|
| 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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. predicateReadOnlySpanPredicate<T>- A function to test the value for a condition.
messagestring?- A composite format string for the message of the exception, or
nullto 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
ArgumentNullExceptionpredicateisnull.ArgumentExceptionpredicatereturnsfalsefor the value ofthis.
SpanParam<T>.Empty(string?)
Throws an ArgumentException if the value of a span parameter is not empty.
Type parameters
T- The type of the items of the span.
Parameters
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. messagestring?- A composite format string for the message of the exception, or
nullto 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
thisholds 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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length that the value must have.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis not equal tosize.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. otherReadOnlySpan<T>- The read-only span whose length the value must have.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}is the length ofother, 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
thisis not equal to the length ofother.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length to compare with.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis less than or equal tosize.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length to compare with.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis less thansize.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length to compare with.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis greater than or equal tosize.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length to compare with.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis greater thansize.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. otherReadOnlySpan<T>- The read-only span whose length to compare with.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}is the length ofother, 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
thisis greater than the length ofother.
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
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. sizeint- The length that the value must not have.
messagestring?- A composite format string for the message of the exception, or
nullto use the default message. The format item{0}is the name of the parameter,{1}is its text,{2}issize, 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
thisis equal tosize.
SpanParam<T>.NotEmpty(string?)
Throws an ArgumentException if the value of a span parameter is empty.
Type parameters
T- The type of the items of the span.
Parameters
thisSpanParam<T>- The
SpanParam<T>that holds the span to check. messagestring?- A composite format string for the message of the exception, or
nullto 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
thisholds 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.
Parameters
thisSpanParam<char>- The
SpanParam<T>that holds the span of characters to check. messagestring?- A composite format string for the message of the exception, or
nullto 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
thisis 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.
Parameters
thisSpanParam<char>- The
SpanParam<T>that holds the span of characters to check. messagestring?- A composite format string for the message of the exception, or
nullto 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
thisholds 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.