Struct Result<T>
- Namespace
- Executables
- Assembly
- executables.dll
Represents either a successful value or a failure exception.
public readonly struct Result<T> : IEquatable<Result<T>>
Type Parameters
TSuccessful value type.
- Implements
-
IEquatable<Result<T>>
- Inherited Members
Properties
Exception
Gets the failure exception, or null for successful results.
public Exception Exception { get; }
Property Value
IsFailure
Gets a value indicating whether the result represents failure.
public bool IsFailure { get; }
Property Value
IsSuccess
Gets a value indicating whether the result represents success.
public bool IsSuccess { get; }
Property Value
Value
Gets the successful value or throws when result is a failure.
public T Value { get; }
Property Value
- T
Exceptions
- InvalidOperationException
Throws when result is a failure.
Methods
Equals(Result<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Result<T> other)
Parameters
otherResult<T>An object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromException(Exception)
Creates a failed result from exception.
public static Result<T> FromException(Exception exception)
Parameters
exceptionExceptionFailure exception.
Returns
- Result<T>
Failed result instance.
Exceptions
- ArgumentNullException
Throws when
exceptionis null.
FromResult(T)
Creates a successful result from value.
public static Result<T> FromResult(T value)
Parameters
valueTSuccessful value.
Returns
- Result<T>
Successful result instance.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ThrowIfFailure()
Throws stored exception when result is a failure.
public void ThrowIfFailure()
ToString()
Returns textual representation of the value or failure exception.
public override string ToString()
Returns
- string
String representation of current result.
TryGetValue(out T)
Attempts to get successful value.
public bool TryGetValue(out T value)
Parameters
valueTWhen this method returns, contains the successful value or default value on failure.
Returns
Operators
operator ==(Result<T>, Result<T>)
public static bool operator ==(Result<T> left, Result<T> right)
Parameters
Returns
operator !=(Result<T>, Result<T>)
public static bool operator !=(Result<T> left, Result<T> right)