Skip to content

Reference

Every public type and operator, grouped by what you do with it. Each row links to the page that explains it with examples.

using Fluent.Unions;               // Result, Result<T>, Option<T>, Loadable<T>, ValidationError(s), [FluentResult<TError>], and all operators
using Fluent.Unions.Validation;    // Is and the EnsureXxx rules
using Fluent.Unions.Abstractions;  // IFromException for your own error type, ResultTypes, result interfaces
using Fluent.Unions.Serialization; // OptionJsonConverter, ResultJsonConverter, UnionJsonConverter, UnionCaseName, UnionCaseNames
using Fluent.Unions.AspNetCore;    // ToHttpResult, WithResultMapping, ResultHttpOptions (Fluent.Unions.AspNetCore)

Types

Type Cases Docs
Result Ok or Exception; default counts as an error Result core concepts
Result<T> T or Exception; default and null count as an error Result core concepts
Option<T> T or None; default holds no value either Option core concepts
Loadable<T> NotLoaded, Loading, T or Exception Loadable
Captured<T> Holder filled by Out(out var value) Result operations
Ok, None, NotLoaded, Loading Marker structs used as cases
ResultErrorException Thrown by Check() for errors that are not exceptions Errors as data
ValidationError, ValidationErrors A failed rule with MemberName, and every failed rule of a value Validation

Creating

Member Result Docs
implicit conversion from T, Exception, Ok, None the matching case Result, Option
Result.Ok, Result<T>.Ok(value), Result.From(value), Result.Error(e), Result<T>.Error(e) explicit creation Result core concepts
Result.Try(...), Result.TryAsync(...) runs code that may throw Error handling
Option.None, Option.Some(value) explicit creation Option core concepts
value.ToOption() from a nullable reference or nullable value type Option conversions
Option.TryParse<T>(text) parses any IParsable<T> / ISpanParsable<T> Option core concepts
Loadable.NotLoaded, Loadable.Loading waiting states Loadable

Members

Member On Docs
IsSuccess, IsError, TryGetError(out error), GetError() Result, Result<T>, and your own result types Result core concepts
TryGetValue(out value), GetValue() Result<T>, your own result types Result core concepts
HasValue, TryGetValue(out value), GetValue() Option<T> Option core concepts
IsNotLoaded, IsLoading, IsLoaded, IsFaulted, TryGetValue, Select, GetValueOrDefault(fallback) Loadable<T> Loadable
var (value, error) = result Result<T> Result core concepts
Value every union, from .NET's IUnion Your own unions

Operators on the value

Operator Result Option Task overloads Docs
Select yes yes yes Result, Option
Chain / SelectMany yes yes yes Result, Option
Where yes yes Option
Chain(step, combine), ChainAwait(step, combine) Result<T> yes Result
Zip (both inputs already evaluated) Result<T> yes yes Result, Option
Ensure(predicate, message), Ensure(predicate, v => exception), EnsureAwait(...) Result<T> yes Result
Result.CombineAll(a, b[, c[, d]]), Result.CombineAllAsync(...) Result<T> tasks Result
ChainAppend(v => ...), ChainAppend((a, b) => ...), ChainAppendAwait(...) Result<T>, tuples up to four elements yes Result
WithValue(value), DiscardValue() Result, Result<T> yes Result
Out(out var value) Result<T> yes yes Result, Option
Unwrap nested results nested options Result, Option
Or(() => ...) yes yes Option operations

Operators on the error

Operator On Docs
Catch(e => ...), Catch((IOException e) => ...), Catch(fallback) results, Task of results, custom types Error handling
OnErrorDo(e => ...), Do(v => ..., e => ...) results, Task of results, custom types Error handling
TapError(e => ...), Tap(v => ..., e => ...) results, Task of results, custom types Error handling
MapError<TTarget, TTargetError>(e => ...) results and custom types, not Task Errors as data
Validate(rules...) Result<T>, Task<Result<T>>, your own result types Validation, Your own Result type
ValidateAnnotations() Result<T>, Task<Result<T>> Validation

Validation rules

Namespace Fluent.Unions.Validation.

API On Docs
Is.NotEmpty, Is.Empty, Is.NotWhiteSpace, Is.WhiteSpace and the format, character class and Includes* predicates (Is.MatchesEmail, Is.Alpha, Is.IncludesDigit, ...) string?, used as method groups Rule catalogue
Is.HasLength(n), Is.LongerThan(n), Is.ShorterThan(n) and the OrEqual forms factories for string? String rules
Is.Contains(text), Is.StartsWith(text), Is.EndsWith(text) and the Not forms, with a StringComparison factories for string? String rules
Is.Matches(regex), Is.Matches(pattern, options), Is.NotMatches(...) factories for string? String rules
EnsureNotEmpty(), EnsureEmpty(), EnsureNotWhiteSpace(), EnsureWhiteSpace() string?, Result<string> String rules
EnsureMatchesEmail(), EnsureMatchesUrl(), EnsureMatchesGuid(), EnsureMatchesIpAddress(), EnsureMatchesPhoneNumber(), EnsureBase64() string?, Result<string> String rules
EnsureAlpha(), EnsureAlphanumeric(), EnsureNumeric() string?, Result<string> String rules
EnsureIncludesDigit(), EnsureIncludesLetter(), EnsureIncludesLetterOrDigit(), EnsureIncludesLower(), EnsureIncludesUpper(), EnsureIncludesPunctuation(), EnsureIncludesSpecial(), EnsureIncludesSymbol(), EnsureIncludesWhiteSpace() string?, Result<string> String rules
EnsureHasLength(n), EnsureLongerThan(n), EnsureLongerThanOrEqual(n), EnsureShorterThan(n), EnsureShorterThanOrEqual(n) string?, Result<string> String rules
EnsureContains(text), EnsureNotContains(text), EnsureStartsWith(text), EnsureNotStartsWith(text), EnsureEndsWith(text), EnsureNotEndsWith(text) string?, Result<string> String rules
EnsureMatches(regex), EnsureMatches(pattern, options), EnsureNotMatches(...) string?, Result<string> String rules
value.Ensure(predicate, message), value.Ensure(predicate, v => exception) any T, returns Result<T> Rule catalogue
Is.Positive, Is.Negative, Is.NonPositive, Is.NonNegative, Is.Zero, Is.NonZero T : INumberBase<T>, used as method groups Number rules
Is.Even, Is.Odd, Is.DivisibleBy(divisor) T : IBinaryInteger<T> Number rules
Is.GreaterThan(bound), Is.GreaterThanOrEqual(bound), Is.LessThan(bound), Is.LessThanOrEqual(bound), Is.InRange(min, max) factories for T : IComparable<T> Number rules
EnsurePositive(), EnsureNegative(), EnsureNonPositive(), EnsureNonNegative(), EnsureZero(), EnsureNonZero() T : INumberBase<T>, Result<T> Number rules
EnsureEven(), EnsureOdd(), EnsureDivisibleBy(divisor) T : IBinaryInteger<T>, Result<T> Number rules
EnsureGreaterThan(bound), EnsureGreaterThanOrEqual(bound), EnsureLessThan(bound), EnsureLessThanOrEqual(bound), EnsureInRange(min, max) T : IComparable<T>, Result<T> Number rules
Is.Null, Is.NotNull, Is.Some, Is.None any T and Option<T>, used as method groups General rules
Is.EqualTo(expected), Is.NotEqualTo(other), Is.In(...), Is.NotIn(...) factories for any T General rules
EnsureEqualTo(expected), EnsureNotEqualTo(other), EnsureIn([...]), EnsureNotIn([...]) any T, Result<T> General rules
EnsureNotNull() any T, value only General rules
EnsureSome(), EnsureNone() Option<T>, Result<Option<T>> General rules
Is.NotEmpty, Is.Empty, Is.Unique IEnumerable<TItem>?, used as method groups Collection rules
Is.Unique(comparer), Is.HasCount(n), Is.HasMinCount(n), Is.HasMaxCount(n) factories for collections Collection rules
Is.ContainsItem(item), Is.NotContainsItem(item), Is.AllMatch(predicate), Is.AnyMatch(predicate), Is.NoneMatch(predicate) factories for IEnumerable<TItem>? Collection rules
EnsureNotEmpty(), EnsureEmpty(), EnsureUnique(), EnsureUnique(comparer), EnsureHasCount(n), EnsureHasMinCount(n), EnsureHasMaxCount(n) any collection, Result<TCollection> Collection rules
EnsureContainsItem(item), EnsureNotContainsItem(item), EnsureAllMatch(predicate), EnsureAnyMatch(predicate), EnsureNoneMatch(predicate) any collection, Result<TCollection> Collection rules
Is.InPast(timeProvider), Is.InPastOrPresent(...), Is.InFuture(...), Is.InFutureOrPresent(...), also taking a DateTimeOffset or DateTime as now factories for DateTimeOffset and DateTime Date, time and other value rules
EnsureInPast(timeProvider), EnsureInPastOrPresent(...), EnsureInFuture(...), EnsureInFutureOrPresent(...), also taking now DateTimeOffset, Result<DateTimeOffset>; with a DateTime now: DateTime, Result<DateTime> Date, time and other value rules
Is.Positive, Is.Negative, Is.NonPositive, Is.NonNegative, Is.Zero, Is.NonZero and the matching Ensure* rules TimeSpan, Result<TimeSpan> Date, time and other value rules
Is.Digit, Is.Letter, Is.LetterOrDigit, Is.Lower, Is.Upper, Is.Punctuation, Is.Special, Is.Symbol, Is.WhiteSpace and the matching Ensure* rules char, Result<char> Date, time and other value rules
Is.NotEmpty, Is.Empty and EnsureNotEmpty(), EnsureEmpty() Guid, Result<Guid> Date, time and other value rules
Is.True, Is.False and EnsureTrue(), EnsureFalse() bool, Result<bool> Date, time and other value rules
Is.Defined, EnsureDefined() TEnum : struct, Enum, Result<TEnum> Date, time and other value rules

Side effects

Operator Docs
Do(v => ...), Finally(() => ...) Result operations
Tap(v => ...), TapAwait(async v => ...) Result operations
OnNoneDo(() => ...), Do(v => ..., () => ...) Option operations

Leaving the chain

Operator On Docs
Match(...) results and options (two callbacks), Loadable<T> (four), custom types Result, Option
GetValueOrDefault(), GetValueOrDefault(fallback), GetValueOrDefault(() => ...) results, options; Loadable<T> takes a fallback Result, Option
DefaultIfEmpty(fallback), DefaultIfEmpty(() => ...) options Option
Check() results, custom types Error handling
ToNullable() Option<T> of a struct Option conversions

Conversions

Operator From → to Docs
ToOption() Result<T> → Option<T>, Loadable<T> → Option<T> Option conversions
ToResult(() => error) Option<T>, T? (nullable reference or value type) → Result<T> Option conversions
Transpose() Option<Result<T>> ↔ Result<Option<T>> Option conversions
ToLoadable() Result<T> / Task<Result<T>> → Loadable<T> Loadable
implicit Result<T> → Result Result core concepts

Sequences

Operator On Docs
Combine(), CombineAll(), Partition(), Values(), Errors() IEnumerable<Result<T>> Result collections
Combine(), Values() IEnumerable<Option<T>> Option collections
FirstOrNone(), LastOrNone(), SingleOrNone(), ElementAtOrNone(i) IEnumerable<T> Option collections
GetValueOrNone(key) IReadOnlyDictionary<TKey, TValue> Option collections

Async

Member Docs
Task overloads of the operators, SelectAwait, ChainAwait, EnsureAwait, ChainAppendAwait, WhereAwait, DoAwait, TapAwait, CatchAwait, FinallyAwait Task pipelines
Result.WhenAll(tasks), Result.Retry(...), Result.RetryAsync(...), task.Timeout(duration) Concurrency and resilience
Values(), Errors(), CombineAsync() on IAsyncEnumerable Streams

Your own Result type and your own unions

Member Docs
[FluentResult<TError>] on a readonly partial struct, with CaseConversions Your own Result type
Capture = ExceptionCapture.All or ExceptionCapture.Declared, Propagate = [typeof(...)] on the attribute Capture policy
Every operator of Result<T> and Result, generated for your type Your own Result type
IFromException<TSelf> on the error type, or FromException on the struct Your own Result type
A union as the error type, case conversions, exhaustive switch Errors as data
ResultTypes.IsResult(type), ResultTypes.ErrorType(type), ResultTypes.ValueType(type) Runtime checks for any result type
union.Is<TCase>(), union.As<TCase>() Your own unions
IResult<TSelf, T, TError>, IErrorResult<TSelf, TError>, IFluentResult<TSelf, T, TError>, IFluentUnitResult<TSelf, TError> Implemented by declared types, not by hand. The integration packages accept any type that implements them
Hand-written result types and Result<T, TError> from 0.3.0 Removed, see Migrating

FluentValidation

Package Fluent.Unions.FluentValidation, namespace Fluent.Unions.FluentValidation.

Member On Docs
ValidateToResult(instance), ValidateToResultAsync(instance, cancellationToken) IValidator<T> FluentValidation
Validate(validator), ValidateAsync(validator, cancellationToken) Result<T> FluentValidation
Validate(validator), Validate(validator, map), ValidateAsync(validator, cancellationToken), ValidateAsync(validator, map, cancellationToken) custom types FluentValidation
RuleForSome(expression) AbstractValidator<T>, Option<T> properties FluentValidation

Polly

Package Fluent.Unions.Polly, namespace Fluent.Unions.Polly.

Member On Docs
HandleError(), HandleError(predicate) PredicateBuilder<Result<T>> Polly
ExecuteResultAsync(operation, cancellationToken) ResiliencePipeline<Result<T>>, ResiliencePipeline Polly
ToResult() Outcome<Result<T>> Polly
HandleError<TResult, TError>(), HandleError<TResult, TError>(predicate) PredicateBuilder<TResult>, custom types (explicit type arguments) Polly
ExecuteResultAsync<TResult, TError>(operation, cancellationToken) ResiliencePipeline<TResult>, ResiliencePipeline, custom types (explicit type arguments) Polly
ToResult<TResult, TError>() Outcome<TResult>, custom types (explicit type arguments) Polly

OpenAPI

Package Fluent.Unions.OpenApi, namespace Fluent.Unions.OpenApi.

Member On Docs
AddFluentUnions() OpenApiOptions OpenAPI
OptionSchemaTransformer IOpenApiSchemaTransformer for Option<T> OpenAPI

AwesomeAssertions

Package Fluent.Unions.AwesomeAssertions, namespace Fluent.Unions.AwesomeAssertions.

Member On Docs
Should() Result, Result<T>, Option<T>, custom types AwesomeAssertions
BeOk(), BeError(), BeError<TException>(), BeError<TException>(predicate), BeAggregateError() ResultAssertions, ResultAssertions<T> AwesomeAssertions
BeOk() (with Which), BeOkWithValue(value), BeOkMatching(predicate), BeOkSatisfying(assertion) ResultAssertions<T> AwesomeAssertions
BeOk() (with Which), BeOkWithValue(value), BeOkMatching(predicate), BeError() (with Which), BeError<TCase>(), BeError<TCase>(predicate) CustomResultAssertions<TSelf, T, TError> AwesomeAssertions
BeSome() (with Which), BeSomeWithValue(value), NotBeSomeWithValue(value), BeSomeMatching(predicate), BeSomeSatisfying(assertion), BeNone() OptionAssertions<T> AwesomeAssertions
WithMessage(pattern), WithMessageContaining(text) ErrorAssertions<TException> AwesomeAssertions
WithInnerCount(count), WithInner<TException>(), WithInnerMessage(pattern) AggregateErrorAssertions AwesomeAssertions

Dapper

Package Fluent.Unions.Dapper, namespace Fluent.Unions.Dapper.

Member On Docs
Register<T>() FluentUnionsDapper, registers Option<T> Dapper
Register() FluentUnionsDapper, registers Option<T> for the common database types Dapper
OptionTypeHandler<T> SqlMapper.TypeHandler<Option<T>> Dapper

Refit

Package Fluent.Unions.Refit, namespace Fluent.Unions.Refit.

Member On Docs
ToResult() IApiResponse, Task<IApiResponse> Refit
ToResult<T>() IApiResponse<T>, Task<IApiResponse<T>>, Task<ApiResponse<T>> Refit
ToOptionalResult<T>() IApiResponse<T>, Task<IApiResponse<T>>, Task<ApiResponse<T>> Refit

FluentAssertions

Package Fluent.Unions.FluentAssertions, namespace Fluent.Unions.FluentAssertions.

Member On Docs
Should() Result, Result<T>, Option<T>, custom types FluentAssertions
BeOk(), BeError(), BeError<TException>(), BeError<TException>(predicate), BeAggregateError() ResultAssertions, ResultAssertions<T> FluentAssertions
BeOk() (with Which), BeOkWithValue(value), BeOkMatching(predicate), BeOkSatisfying(assertion) ResultAssertions<T> FluentAssertions
BeOk() (with Which), BeOkWithValue(value), BeOkMatching(predicate), BeError() (with Which), BeError<TCase>(), BeError<TCase>(predicate) CustomResultAssertions<TSelf, T, TError> FluentAssertions
BeSome() (with Which), BeSomeWithValue(value), NotBeSomeWithValue(value), BeSomeMatching(predicate), BeSomeSatisfying(assertion), BeNone() OptionAssertions<T> FluentAssertions
WithMessage(pattern), WithMessageContaining(text) ErrorAssertions<TException> FluentAssertions
WithInnerCount(count), WithInner<TException>(), WithInnerMessage(pattern) AggregateErrorAssertions FluentAssertions

Serilog

Package Fluent.Unions.Serilog, namespace Fluent.Unions.Serilog.

Member On Docs
WithFluentUnions() LoggerDestructuringConfiguration (.Destructure.WithFluentUnions()) Serilog
UnionDestructuringPolicy IDestructuringPolicy for Result, Result<T>, your own result types, Option<T>, Loadable<T> Serilog

Newtonsoft.Json

Package Fluent.Unions.NewtonsoftJson, namespace Fluent.Unions.NewtonsoftJson.

Member On Docs
AddFluentUnions() JsonSerializerSettings Newtonsoft.Json
OptionJsonConverter Option<T> Newtonsoft.Json
ResultJsonConverter Result, Result<T>, your own result types Newtonsoft.Json
UnionJsonConverter your own unions Newtonsoft.Json

Mediator

Package Fluent.Unions.Mediator, namespace Fluent.Unions.Mediator.

Member On Docs
ExceptionToResultBehavior<TMessage, TResponse> pipeline behavior; acts when TResponse is a result type with any error type, other responses pass through Mediator and MediatR
ValidationToResultBehavior<TMessage, TResponse> pipeline behavior, same rule Mediator and MediatR

MediatR

Package Fluent.Unions.MediatR, namespace Fluent.Unions.MediatR.

Member On Docs
ExceptionToResultBehavior<TRequest, TResponse> pipeline behavior; acts when TResponse is a result type with any error type, other responses pass through Mediator and MediatR
ValidationToResultBehavior<TRequest, TResponse> pipeline behavior, same rule Mediator and MediatR

MongoDB

Package Fluent.Unions.MongoDB, namespace Fluent.Unions.MongoDB.

Member On Docs
Register() FluentUnionsBson MongoDB
OptionSerializer<T> Option<T> MongoDB
OmitNoneConvention ConventionPack, Option<T> members MongoDB
ResultSerializer<TResult> Result, Result<T>, your own result types (refuses) MongoDB

Swashbuckle

Package Fluent.Unions.Swashbuckle, namespace Fluent.Unions.Swashbuckle.

Member On Docs
AddFluentUnions(), OptionSchemaFilter SwaggerGenOptions, ISchemaFilter Swashbuckle

NSwag

Package Fluent.Unions.NSwag, namespace Fluent.Unions.NSwag.

Member On Docs
AddFluentUnions(), OptionSchemaProcessor OpenApiDocumentGeneratorSettings, ISchemaProcessor NSwag

Testing

Packages Fluent.Unions.Shouldly, .TUnit, .NUnit and .Xunit, namespaces of the same names.

Member On Docs
ShouldBeOk(), ShouldBeError(), ShouldBeError<TException>(), ShouldBeError<TCase>() on your own result types, ShouldBeSome(), ShouldBeNone() Result, Result<T>, your own result types, Option<T> (Shouldly) Testing
IsOk(), IsError(), IsError<TException>(), IsSome(), IsNone(); AsResult().ErrorCase<TCase>() for your own result types Assert.That of Result, Result<T>, your own result types, Option<T> (TUnit) Testing
IsResult.Ok, Error, OkWith, ErrorWith, ErrorOfType<TError>() (also a case of an error union); IsOption.Some, None, SomeWith UnionConstraint (NUnit) Testing
ResultAssert.Ok, Error, Error<TException>, Error<TCase> on your own result types; OptionAssert.Some, None Result, Result<T>, your own result types, Option<T> (xUnit v3) Testing

Mapping

Packages Fluent.Unions.Mapster and Fluent.Unions.AutoMapper, namespaces Fluent.Unions.Mapster and Fluent.Unions.AutoMapper.

Member On Docs
AddFluentUnions() TypeAdapterConfig (Mapster) Mapping
AddFluentUnions() IMapperConfigurationExpression (AutoMapper) Mapping

HotChocolate

Package Fluent.Unions.HotChocolate, namespace Fluent.Unions.HotChocolate.

Member On Docs
AddFluentUnions() IRequestExecutorBuilder HotChocolate

MessagePack

Package Fluent.Unions.MessagePack, namespace Fluent.Unions.MessagePack.

Member On Docs
WithFluentUnions() MessagePackSerializerOptions MessagePack
UnionsResolver.Instance IFormatterResolver MessagePack
OptionFormatter<T> Option<T> members MessagePack

Orleans

Package Fluent.Unions.Orleans, namespace Fluent.Unions.Orleans.

Member On Docs
AddFluentUnions() ISerializerBuilder Orleans
OptionConverter<T>, OptionSurrogate<T> Option<T> Orleans

gRPC

Package Fluent.Unions.Grpc, namespace Fluent.Unions.Grpc.

Member On Docs
ToResult() AsyncUnaryCall<T>, AsyncClientStreamingCall<TRequest, TResponse> gRPC
ToRpcException(options) Exception gRPC
Map<T>(statusCode, exposeMessage) ResultGrpcOptions gRPC
ResultServerInterceptor gRPC server interceptor gRPC

Verify

Package Fluent.Unions.Verify, namespace Fluent.Unions.Verify.

Member On Docs
VerifyFluentUnions.Initialize() static class VerifyFluentUnions Verify

Tracing

Member On Docs
RecordResult(result) Activity?, with Result, Result<T> or your own result type (generated overload) Tracing

Serialization

Namespace Fluent.Unions.Serialization.

Type Docs
OptionJsonConverter (applied to Option<T>), ResultJsonConverter (refuses results), UnionJsonConverter Serialization
OptionJsonConverter<T>, UnionJsonConverter<TUnion>: the same JSON as the factories, registered or applied per type for native AOT and trimmed apps AOT and trimming
[UnionCaseName(typeof(Case), "name", Aliases = [...])] on a union: a stable case name Stable case names
UnionCaseNames.For(unionType): the case names of a union; keeps the union's constructors in trimmed apps AOT and trimming

ASP.NET Core (Fluent.Unions.AspNetCore)

Member Docs
ToHttpResult() on results, options and their Task versions HTTP results
ToHttpResult(onError) and, with TError : Exception, ToHttpResult() on your own result types (no Task overload) HTTP results
WithResultMapping(), ResultEndpointFilter Endpoint filter
WithResultMapping() on handlers that return custom result types Endpoint filter
ResultHttpOptions.Map<TException>(statusCode) Error mapping

Analyzer

Rule Docs
FLU0001: the result of a call is not used Analyzer
FLU0002: an async lambda passed to a synchronous operator Analyzer
FLU0003: an async lambda that becomes async void Analyzer
FLU0004: a type argument that overlaps another case Analyzer
FLU0005: a nullable type argument Analyzer
FLU0006: Select that returns a nested result Analyzer
FLU0007: a result created with default Analyzer
FLU0008: a result that is serialized to JSON Analyzer
FLU0009: FromException or FromError that throws or returns null Analyzer
FLU0010: GetValue() or GetError() without a check Analyzer
FLU0011: a cast of Value Analyzer
FLU0012: a throw in a method that returns a result Analyzer
FLU0013: ToOption() that drops an error Analyzer
FLU0101: a [FluentResult] declaration that is not supported Analyzer
FLU0102: an error type that cannot represent an unexpected exception Analyzer
FLU0103: a case of the error union without a conversion Analyzer
FLU0104: Capture = ExceptionCapture.Declared that has no effect Analyzer
FLU0105: a type in Propagate that is not an exception Analyzer

Back to index: Docs index