RefParamExtensions Class

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

public static class RefParamExtensions

Remarks

A check throws an exception if the value of the parameter is not valid. Otherwise, it returns a RefParam<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. The format item {0} is the name of the parameter. The value has no format item, because a ref struct cannot be converted to an object.

This type is not available in the netstandard and .NET Framework builds of Louis, because their BCL has no RuntimeFeature.ByRefLikeGenerics.

Methods

NameDescription
RefParam<T>.Checked(Func<T, bool>, string?)Throws an ArgumentException if the value of a parameter does not satisfy a condition.

RefParam<T>.Checked(Func<T, bool>, string?)

Available in: net10.0net11.0(not available in the other target frameworks of the package)

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

extension<T>(RefParam<T> @this) where T : allows ref struct
{
    public RefParam<T> Checked(Func<T, bool> predicate, string? message = null)
}

Type parameters

T
The type of the parameter.

Parameters

this RefParam<T>
The RefParam<T> that holds the value to check.
predicate Func<T, bool>
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.

Returns

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

Exceptions

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