Class Result
Represents extension methods for type Result<T>.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class Result
Methods
| Edit this page View SourceCoalesce<T>(in Result<T>, in Result<T>)
Returns the second result if the first is unsuccessful.
Declaration
public static ref readonly Result<T> Coalesce<T>(this in Result<T> first, in Result<T> second)
Parameters
| Type | Name | Description |
|---|---|---|
| Result<T> | first | The first result. |
| Result<T> | second | The second result. |
Returns
| Type | Description |
|---|---|
| Result<T> | The second result if the first is unsuccessful; otherwise, the first result. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value. |
EnsureNotNull<T>(Result<T?>)
Ensures that the specified result doesn't contain null value.
Declaration
public static Result<T> EnsureNotNull<T>(this Result<T?> result) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| Result<T> | result | The result to be checked. |
Returns
| Type | Description |
|---|---|
| Result<T> | The result containing non-null value; or NullReferenceException as an error. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the result. |
EnsureNotNull<T, TException>(Result<T?>)
Ensures that the specified result doesn't contain null value.
Declaration
public static Result<T> EnsureNotNull<T, TException>(this Result<T?> result) where T : class where TException : Exception, new()
Parameters
| Type | Name | Description |
|---|---|---|
| Result<T> | result | The result to be checked. |
Returns
| Type | Description |
|---|---|
| Result<T> | The result containing non-null value; or |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the result. |
| TException | The type of the exception to be returned from the null result. |
FromException<T>(Exception)
Creates a new instance of Result<T> from the specified exception.
Declaration
public static Result<T> FromException<T>(Exception e)
Parameters
| Type | Name | Description |
|---|---|---|
| Exception | e | The exception to be placed to the container. |
Returns
| Type | Description |
|---|---|
| Result<T> | The exception encapsulated by Result<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
FromValue<T>(T)
Creates a new instance of Result<T> from the specified value.
Declaration
public static Result<T> FromValue<T>(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to be placed to the container. |
Returns
| Type | Description |
|---|---|
| Result<T> | The value encapsulated by Result<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
GetUnderlyingType(Type)
Returns the underlying type argument of the specified result type.
Declaration
public static Type? GetUnderlyingType(Type resultType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | resultType | Result type. |
Returns
| Type | Description |
|---|---|
| Type | Underlying type argument of the result type; otherwise, null. |
IsResult(Type)
Indicates that the specified type is the result type.
Declaration
public static bool IsResult(this Type resultType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | resultType | The type of Result<T>. |
Returns
| Type | Description |
|---|---|
| bool |
OrNull<T>(in Result<T>)
If a result is successful, returns it, otherwise null.
Declaration
public static T? OrNull<T>(this in Result<T> result) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Result<T> | result | The result. |
Returns
| Type | Description |
|---|---|
| T? | Nullable value. |
Type Parameters
| Name | Description |
|---|---|
| T | Value type. |
OrNull<T, TError>(in Result<T, TError>)
If a result is successful, returns it, otherwise null.
Declaration
public static T? OrNull<T, TError>(this in Result<T, TError> result) where T : struct where TError : struct, Enum
Parameters
| Type | Name | Description |
|---|---|---|
| Result<T, TError> | result | The result. |
Returns
| Type | Description |
|---|---|
| T? | Nullable value. |
Type Parameters
| Name | Description |
|---|---|
| T | Value type. |
| TError | The type of the error code. |