Show / Hide Table of Contents

Struct Result<T>

Represents a result of operation which can be actual result or exception.

Implements
ISerializable
Inherited Members
ValueType.Equals(Object)
ValueType.GetHashCode()
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: DotNext
Assembly: DotNext.dll
Syntax
[Serializable]
public struct Result<T> : ISerializable
Type Parameters
Name Description
T

The type of the value stored in the Result monad.

Constructors

| Improve this Doc View Source

Result(T)

Initializes a new successful result.

Declaration
public Result(T value)
Parameters
Type Name Description
T value

The value to be stored as result.

| Improve this Doc View Source

Result(Exception)

Initializes a new unsuccessful result.

Declaration
public Result(Exception error)
Parameters
Type Name Description
Exception error

The exception representing error. Cannot be null.

Properties

| Improve this Doc View Source

Error

Gets exception associated with this result.

Declaration
public Exception Error { get; }
Property Value
Type Description
Exception
| Improve this Doc View Source

IsSuccessful

Indicates that the result is successful.

Declaration
public bool IsSuccessful { get; }
Property Value
Type Description
Boolean

true if this result is successful; false if this result represents exception.

| Improve this Doc View Source

Value

Extracts actual result.

Declaration
public T Value { get; }
Property Value
Type Description
T
Exceptions
Type Condition
Exception

This result is not successful.

Methods

| Improve this Doc View Source

Box()

Gets boxed representation of the result.

Declaration
public Result<object> Box()
Returns
Type Description
Result<Object>

The boxed representation of the result.

| Improve this Doc View Source

Convert<TResult>(ValueFunc<T, TResult>)

If successful result is present, apply the provided mapping function hiding any exception caused by the converter.

Declaration
public Result<TResult> Convert<TResult>(in ValueFunc<T, TResult> converter)
Parameters
Type Name Description
ValueFunc<T, TResult> converter

A mapping function to be applied to the value, if present.

Returns
Type Description
Result<TResult>

The conversion result.

Type Parameters
Name Description
TResult

The type of the result of the mapping function.

| Improve this Doc View Source

Convert<TResult>(Converter<T, TResult>)

If successful result is present, apply the provided mapping function hiding any exception caused by the converter.

Declaration
public Result<TResult> Convert<TResult>(Converter<T, TResult> converter)
Parameters
Type Name Description
Converter<T, TResult> converter

A mapping function to be applied to the value, if present.

Returns
Type Description
Result<TResult>

The conversion result.

Type Parameters
Name Description
TResult

The type of the result of the mapping function.

| Improve this Doc View Source

FromOptional(Optional<T>)

Creates Result<T> from Optional<T> instance.

Declaration
public static Result<T> FromOptional(in Optional<T> optional)
Parameters
Type Name Description
Optional<T> optional

The optional value.

Returns
Type Description
Result<T>

The converted optional value.

| Improve this Doc View Source

Or(T)

Returns the value if present; otherwise return default value.

Declaration
public T Or(T defaultValue)
Parameters
Type Name Description
T defaultValue

The value to be returned if this result is unsuccessful.

Returns
Type Description
T

The value, if present, otherwise defaultValue.

| Improve this Doc View Source

OrDefault()

Returns the value if present; otherwise return default value.

Declaration
public T OrDefault()
Returns
Type Description
T

The value, if present, otherwise default.

| Improve this Doc View Source

OrInvoke(ValueFunc<T>)

Returns the value if present; otherwise invoke delegate.

Declaration
public T OrInvoke(in ValueFunc<T> defaultFunc)
Parameters
Type Name Description
ValueFunc<T> defaultFunc

A delegate to be invoked if value is not present.

Returns
Type Description
T

The value, if present, otherwise returned from delegate.

| Improve this Doc View Source

OrInvoke(ValueFunc<Exception, T>)

Returns the value if present; otherwise invoke delegate.

Declaration
public T OrInvoke(in ValueFunc<Exception, T> defaultFunc)
Parameters
Type Name Description
ValueFunc<Exception, T> defaultFunc

A delegate to be invoked if value is not present.

Returns
Type Description
T

The value, if present, otherwise returned from delegate.

| Improve this Doc View Source

OrInvoke(Func<T>)

Returns the value if present; otherwise invoke delegate.

Declaration
public T OrInvoke(Func<T> defaultFunc)
Parameters
Type Name Description
Func<T> defaultFunc

A delegate to be invoked if value is not present.

Returns
Type Description
T

The value, if present, otherwise returned from delegate.

| Improve this Doc View Source

OrInvoke(Func<Exception, T>)

Returns the value if present; otherwise invoke delegate.

Declaration
public T OrInvoke(Func<Exception, T> defaultFunc)
Parameters
Type Name Description
Func<Exception, T> defaultFunc

A delegate to be invoked if value is not present.

Returns
Type Description
T

The value, if present, otherwise returned from delegate.

| Improve this Doc View Source

ToString()

Returns textual representation of this object.

Declaration
public override string ToString()
Returns
Type Description
String

The textual representation of this object.

Overrides
ValueType.ToString()
| Improve this Doc View Source

TryGet()

Converts the result into Optional<T>.

Declaration
public Optional<T> TryGet()
Returns
Type Description
Optional<T>

Option monad representing value in this monad.

| Improve this Doc View Source

TryGet(out T)

Attempts to extract value from container if it is present.

Declaration
public bool TryGet(out T value)
Parameters
Type Name Description
T value

Extracted value.

Returns
Type Description
Boolean

true if value is present; otherwise, false.

Operators

| Improve this Doc View Source

BitwiseAnd(Result<T>, Result<T>)

Indicates that both results are successful.

Declaration
public static bool operator &(in Result<T> left, in Result<T> right)
Parameters
Type Name Description
Result<T> left

The first result to check.

Result<T> right

The second result to check.

Returns
Type Description
Boolean

true if both results are successful; otherwise, false.

| Improve this Doc View Source

Explicit(Optional<T> to Result<T>)

Converts Optional<T> to Result<T>.

Declaration
public static explicit operator Result<T>(in Optional<T> optional)
Parameters
Type Name Description
Optional<T> optional

The optional value.

Returns
Type Description
Result<T>

The result representing optional value.

| Improve this Doc View Source

Explicit(Result<T> to T)

Extracts actual result.

Declaration
public static explicit operator T(in Result<T> result)
Parameters
Type Name Description
Result<T> result

The result object.

Returns
Type Description
T
| Improve this Doc View Source

False(Result<T>)

Indicates that the result represents error.

Declaration
public static bool operator false (in Result<T> result)
Parameters
Type Name Description
Result<T> result

The result to check.

Returns
Type Description
Boolean

false if this result is successful; true if this result represents exception.

| Improve this Doc View Source

Implicit(T to Result<T>)

Converts value into the result.

Declaration
public static implicit operator Result<T>(T result)
Parameters
Type Name Description
T result

The result to be converted.

Returns
Type Description
Result<T>

The result representing result value.

| Improve this Doc View Source

Implicit(Result<T> to Optional<T>)

Converts the result into Optional<T>.

Declaration
public static implicit operator Optional<T>(in Result<T> result)
Parameters
Type Name Description
Result<T> result

The result to be converted.

Returns
Type Description
Optional<T>
| Improve this Doc View Source

True(Result<T>)

Indicates that the result is successful.

Declaration
public static bool operator true (in Result<T> result)
Parameters
Type Name Description
Result<T> result

The result to check.

Returns
Type Description
Boolean

true if this result is successful; false if this result represents exception.

Explicit Interface Implementations

| Improve this Doc View Source

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info
StreamingContext context

Implements

System.Runtime.Serialization.ISerializable

Extension Methods

Result.Coalesce<T>(Result<T>, Result<T>)
Sequence.Skip<TEnumerator, T>(ref TEnumerator, Int32)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX