Struct FluentResult<T>
Represents the result of a fluent operation, allowing for chained conditional checks and transformations.
public struct FluentResult<T>
Type Parameters
TThe type of the value being evaluated.
- Inherited Members
- Extension Methods
Constructors
FluentResult(T, bool, string)
Initializes a new instance of the FluentResult<T> struct with the provided value and result.
public FluentResult(T value, bool success, string variableName = "")
Parameters
valueTThe value to wrap.
successboolIndicates whether the operation was successful.
variableNamestringname of the variable passed as
valueparameter
FluentResult(T, string)
Initializes a new instance of the FluentResult<T> struct with the provided value, marking it as successful.
public FluentResult(T value, string variableName = "")
Parameters
valueTThe value to wrap.
variableNamestringname of the variable passed as
valueparameter
Properties
Result
Gets a value indicating whether the operation was successful.
public readonly bool Result { get; }
Property Value
Value
Gets the value being evaluated.
public readonly T Value { get; }
Property Value
- T
VariableName
Gets the name of the initial value
public readonly string VariableName { get; }
Property Value
Methods
Failure()
Marks the operation as failed.
public readonly FluentResult<T> Failure()
Returns
- FluentResult<T>
A new FluentResult<T> marked as failed.
Is(Func<T, bool>)
Checks if the value verifies the given predicate.
public readonly FluentResult<T> Is(Func<T, bool> test)
Parameters
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether verifies the given predicate.
IsEqualTo<CT>(CT)
Checks if the value is equal to the comparison value.
public readonly FluentResult<T> IsEqualTo<CT>(CT comparisonValue)
Parameters
comparisonValueCTThe value to compare against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the values are equal.
Type Parameters
CTThe type of the comparison value.
IsGreaterOrEqualsThan<CT>(CT)
Checks if the value is greater than or equal to the comparison value.
public readonly FluentResult<T> IsGreaterOrEqualsThan<CT>(CT comparisonValue)
Parameters
comparisonValueCTThe value to compare against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is greater than or equal to the comparison value.
Type Parameters
CTThe type of the comparison value.
IsGreaterThan<CT>(CT)
Checks if the value is greater than the comparison value.
public readonly FluentResult<T> IsGreaterThan<CT>(CT comparisonValue)
Parameters
comparisonValueCTThe value to compare against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is greater than the comparison value.
Type Parameters
CTThe type of the comparison value.
IsIn(params T[])
Checks if the value is present in a list of values.
public readonly FluentResult<T> IsIn(params T[] values)
Parameters
valuesT[]An array of values to check against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is in the list.
IsLowerOrEqualsThan<CT>(CT)
Checks if the value is less than or equal to the comparison value.
public readonly FluentResult<T> IsLowerOrEqualsThan<CT>(CT comparisonValue)
Parameters
comparisonValueCTThe value to compare against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is less than or equal to the comparison value.
Type Parameters
CTThe type of the comparison value.
IsLowerThan<CT>(CT)
Checks if the value is less than the comparison value.
public readonly FluentResult<T> IsLowerThan<CT>(CT comparisonValue)
Parameters
comparisonValueCTThe value to compare against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is less than the comparison value.
Type Parameters
CTThe type of the comparison value.
IsNot(Func<T, bool>)
Checks if the value does not verify the given predicate.
public readonly FluentResult<T> IsNot(Func<T, bool> test)
Parameters
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether does not verify the given predicate.
IsNotIn(params T[])
Checks if the value is not present in a list of values.
public readonly FluentResult<T> IsNotIn(params T[] values)
Parameters
valuesT[]An array of values to check against.
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is not in the list.
IsNotNull()
Checks if the value is not null.
public readonly FluentResult<T> IsNotNull()
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is not null.
IsNull()
Checks if the value is null.
public readonly FluentResult<T> IsNull()
Returns
- FluentResult<T>
A new FluentResult<T> indicating whether the value is null.
Not()
Negates the current result.
public readonly FluentResult<T> Not()
Returns
- FluentResult<T>
A new FluentResult<T> with the result negated.
Success()
Marks the operation as successful.
public readonly FluentResult<T> Success()
Returns
- FluentResult<T>
A new FluentResult<T> marked as successful.
Then<RT>(Func<FluentResult<T>, RT>)
Applies a function to the current FluentResult<T> and returns the result.
public readonly RT Then<RT>(Func<FluentResult<T>, RT> func)
Parameters
funcFunc<FluentResult<T>, RT>The function to apply.
Returns
- RT
The result of the function.
Type Parameters
RT
Then<RT>(Func<T, RT>, Func<T, RT>)
Applies one of two functions based on the result of the current FluentResult<T>.
public readonly RT Then<RT>(Func<T, RT> @true, Func<T, RT> @false)
Parameters
trueFunc<T, RT>The function to apply if the result is true.
falseFunc<T, RT>The function to apply if the result is false.
Returns
- RT
The result of the applied function.
Type Parameters
RT
Operators
implicit operator T(FluentResult<T>)
Implicitly converts a FluentResult<T> to its wrapped value.
public static implicit operator T(FluentResult<T> value)
Parameters
valueFluentResult<T>The FluentResult<T> to convert.
Returns
- T