Represents a result of operation which can be the actual result or exception.
Namespace: DotNext Assembly: DotNext.dll Syntaxpublic readonly struct Result<T> : IResultMonad<T, Exception, Result<T>>, IResultMonad<T, Exception>, IOptionMonad<T, Result<T>>, IOptionMonad<T>, ISupplier<object?>, IFunctional<Func<object?>>
Type Parameters Name Description T
The type of the value stored in the Result monad.
Constructors | Edit this page View Source Result(Exception)Initializes a new unsuccessful result.
Declarationpublic Result(Exception error)
Parameters Type Name Description Exception error
The exception representing error. Cannot be null.
| Edit this page View Source Result(T)Initializes a new successful result.
Declaration Parameters Type Name Description T valueThe value to be stored as result.
Properties | Edit this page View Source ErrorGets exception associated with this result.
Declarationpublic Exception? Error { get; }
Property Value | Edit this page View Source IsSuccessful
Indicates that the result is successful.
Declarationpublic bool IsSuccessful { get; }
Property Value Type Description bool
true if this result is successful; false if this result represents exception.
| Edit this page View Source ValueExtracts the actual result.
Declaration Property Value Exceptions Type Condition ExceptionThis result is not successful.
| Edit this page View Source ValueOrDefaultGets the value if present; otherwise return default value.
Declarationpublic T? ValueOrDefault { get; }
Property Value Type Description T
The value, if present, otherwise default
.
Gets a reference to the underlying value.
Declaration[JsonIgnore]
public ref readonly T ValueRef { get; }
Property Value Type Description T
The reference to the result.
Exceptions Type Condition ExceptionThe result is unavailable.
Methods | Edit this page View Source AsTask()Converts this result to Task<TResult>.
Declarationpublic ValueTask<T> AsTask()
Returns Type Description ValueTask<T>
The completed task representing the result.
| Edit this page View Source Box()Gets boxed representation of the result.
Declarationpublic Result<object?> Box()
Returns Type Description Result<object>
The boxed representation of the result.
| Edit this page View Source Convert<TResult>(delegate*<T, TResult>)If the successful result is present, apply the provided mapping function hiding any exception caused by the converter.
Declaration[CLSCompliant(false)]
public Result<TResult> Convert<TResult>(delegate*<T, TResult> converter)
Parameters Type Name Description delegate*<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 TResultThe type of the mapping function result.
| Edit this page View Source Convert<TResult>(Converter<T, TResult>)If the successful result is present, apply the provided mapping function hiding any exception caused by the converter.
Declarationpublic 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 TResultThe type of the mapping function result.
| Edit this page View Source FromOptional(in Optional<T>)Creates Result<T> from Optional<T> instance.
Declarationpublic 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.
| Edit this page View Source Or(T?)Returns the value if present; otherwise return default value.
Declarationpublic T? Or(T? defaultValue)
Parameters Type Name Description T defaultValue
The value to be returned if this result is unsuccessful.
Returns Type Description TThe value, if present, otherwise defaultValue
.
Returns the value if present; otherwise invoke delegate.
Declaration[CLSCompliant(false)]
public T OrInvoke(delegate*<Exception, T> defaultFunc)
Parameters Type Name Description delegate*<Exception, T> defaultFunc
A delegate to be invoked if value is not present.
Returns Type Description TThe value, if present, otherwise returned from delegate.
| Edit this page View Source OrInvoke(delegate*<Exception, T>)Returns the value if present; otherwise invoke delegate.
Declaration[CLSCompliant(false)]
public T OrInvoke(delegate*<Exception, T> defaultFunc)
Parameters Type Name Description delegate*<Exception, T> defaultFunc
A delegate to be invoked if value is not present.
Returns Type Description TThe value, if present, otherwise returned from delegate.
| Edit this page View Source OrInvoke(Func<Exception, T>)Returns the value if present; otherwise invoke delegate.
Declarationpublic 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 TThe value, if present, otherwise returned from delegate.
| Edit this page View Source OrInvoke(Func<T>)Returns the value if present; otherwise invoke delegate.
Declarationpublic 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 TThe value, if present, otherwise returned from delegate.
| Edit this page View Source ToString()Returns textual representation of this object.
Declarationpublic override string ToString()
Returns Type Description string
The textual representation of this object.
Overrides | Edit this page View Source TryGet()Converts the result into Optional<T>.
Declarationpublic Optional<T> TryGet()
Returns Type Description Optional<T>
Option monad representing value in this monad.
| Edit this page View Source TryGet(out T)Attempts to extract value from the container if it is present.
Declarationpublic bool TryGet(out T value)
Parameters Type Name Description T value
Extracted value.
Returns Type Description booltrue if value is present; otherwise, false.
Operators | Edit this page View Source operator &(in Result<T>, in Result<T>)Indicates that both results are successful.
Declarationpublic 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> rightThe second result to check.
Returns Type Description booltrue if both results are successful; otherwise, false.
| Edit this page View Source operator |(in Result<T>, in Result<T>)Tries to return successful result.
Declarationpublic static Result<T> operator |(in Result<T> x, in Result<T> y)
Parameters Type Name Description Result<T> x
The first container.
Result<T> yThe second container.
Returns Type Description Result<T>The first successful result.
| Edit this page View Source operator |(in Result<T>, T?)Returns the value if present; otherwise return default value.
Declarationpublic static T? operator |(in Result<T> result, T? defaultValue)
Parameters Type Name Description Result<T> result
The result to check.
T defaultValueThe value to be returned if this result is unsuccessful.
Returns Type Description TThe value, if present, otherwise defaultValue
.
Converts Optional<T> to Result<T>.
Declarationpublic 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.
| Edit this page View Source explicit operator ValueTask<T>(in Result<T>)Converts the result to Task<TResult>.
Declarationpublic static explicit operator ValueTask<T>(in Result<T> result)
Parameters Type Name Description Result<T> result
The result to be converted.
Returns Type Description ValueTask<T>The completed task representing the result.
| Edit this page View Source explicit operator T(in Result<T>)Extracts actual result.
Declarationpublic static explicit operator T(in Result<T> result)
Parameters Type Name Description Result<T> result
The result object.
Returns | Edit this page View Source operator false(in Result<T>)Checks whether the container has no value.
Declarationpublic static bool operator false(in Result<T> result)
Parameters Type Name Description Result<T> result Returns Type Description bool
true if this container has no value; otherwise, false.
| Edit this page View Source implicit operator Optional<T>(in Result<T>)Converts the result into Optional<T>.
Declarationpublic 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>Option monad representing value in this monad.
| Edit this page View Source implicit operator Result<T>(T)Converts value into the result.
Declarationpublic 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.
Checks whether the container has no value.
Declarationpublic static bool operator !(in Result<T> result)
Parameters Type Name Description Result<T> result Returns Type Description bool
true if this container has no value; otherwise, false.
| Edit this page View Source operator true(in Result<T>)Checks whether the container has value.
Declarationpublic static bool operator true(in Result<T> result)
Parameters Type Name Description Result<T> result Returns Type Description bool
true if this container has value; otherwise, false.
Implements Extension MethodsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4