Struct Attempt<TResult>
Represents the result of an operation attempt.
Namespace: Umbraco.Cms.Core
Assembly: Umbraco.Core.dll
Syntax
public struct Attempt<TResult>
Type Parameters
Name | Description |
---|---|
TResult | The type of the attempted operation result. |
Properties
View SourceException
Gets the exception associated with an unsuccessful attempt.
Declaration
public readonly Exception? Exception { get; }
Property Value
Type | Description |
---|---|
System.Nullable<Exception> |
Result
Gets the attempt result.
Declaration
public readonly TResult Result { get; }
Property Value
Type | Description |
---|---|
TResult |
Success
Gets a value indicating whether this Attempt<TResult> was successful.
Declaration
public readonly bool Success { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
View SourceFail()
Creates a failed attempt.
Declaration
public static Attempt<TResult> Fail()
Returns
Type | Description |
---|---|
Attempt<TResult> | The failed attempt. |
Fail(TResult)
Creates a failed attempt with a result.
Declaration
public static Attempt<TResult> Fail(TResult result)
Parameters
Type | Name | Description |
---|---|---|
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The failed attempt. |
Fail(TResult, Exception)
Creates a failed attempt with a result and an exception.
Declaration
public static Attempt<TResult> Fail(TResult result, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
TResult | result | The result of the attempt. |
Exception | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The failed attempt. |
Fail(Nullable<Exception>)
Creates a failed attempt with an exception.
Declaration
public static Attempt<TResult> Fail(Exception? exception)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<Exception> | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The failed attempt. |
If(Boolean)
Creates a successful or a failed attempt.
Declaration
public static Attempt<TResult> If(bool condition)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The attempt. |
If(Boolean, TResult)
Creates a successful or a failed attempt, with a result.
Declaration
public static Attempt<TResult> If(bool condition, TResult result)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The attempt. |
ResultOr(TResult)
Gets the attempt result, if successful, else a default value.
Declaration
public TResult ResultOr(TResult value)
Parameters
Type | Name | Description |
---|---|---|
TResult | value |
Returns
Type | Description |
---|---|
TResult |
Succeed()
Creates a successful attempt.
Declaration
public static Attempt<TResult> Succeed()
Returns
Type | Description |
---|---|
Attempt<TResult> | The successful attempt. |
Succeed(TResult)
Creates a successful attempt with a result.
Declaration
public static Attempt<TResult> Succeed(TResult result)
Parameters
Type | Name | Description |
---|---|---|
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult> | The successful attempt. |
Operators
View SourceImplicit(Attempt<TResult> to Boolean)
Implicitly operator to check if the attempt was successful without having to access the 'success' property
Declaration
public static implicit operator bool (Attempt<TResult> a)
Parameters
Type | Name | Description |
---|---|---|
Attempt<TResult> | a |
Returns
Type | Description |
---|---|
System.Boolean |