Struct Attempt<TResult, TStatus>
Represents the result of an operation attempt.
Namespace: Umbraco.Core
Assembly: Umbraco.Core.dll
Syntax
[Serializable]
public struct Attempt<TResult, TStatus>
Type Parameters
Name | Description |
---|---|
TResult | The type of the attempted operation result. |
TStatus | The type of the attempted operation status. |
Properties
View SourceException
Gets the exception associated with an unsuccessful attempt.
Declaration
public readonly Exception Exception { get; }
Property Value
Type | Description |
---|---|
System.Exception |
Result
Gets the attempt result.
Declaration
public readonly TResult Result { get; }
Property Value
Type | Description |
---|---|
TResult |
Status
Gets the attempt status.
Declaration
public readonly TStatus Status { get; }
Property Value
Type | Description |
---|---|
TStatus |
Success
Gets a value indicating whether this Attempt<TResult, TStatus> was successful.
Declaration
public readonly bool Success { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
View SourceFail(TStatus)
Creates a failed attempt.
Declaration
public static Attempt<TResult, TStatus> Fail(TStatus status)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The failed attempt. |
Fail(TStatus, TResult)
Creates a failed attempt with a result.
Declaration
public static Attempt<TResult, TStatus> Fail(TStatus status, TResult result)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The failed attempt. |
Fail(TStatus, TResult, Exception)
Creates a failed attempt with a result and an exception.
Declaration
public static Attempt<TResult, TStatus> Fail(TStatus status, TResult result, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
TResult | result | The result of the attempt. |
System.Exception | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The failed attempt. |
Fail(TStatus, Exception)
Creates a failed attempt with an exception.
Declaration
public static Attempt<TResult, TStatus> Fail(TStatus status, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
System.Exception | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The failed attempt. |
If(Boolean, TStatus, TStatus)
Creates a successful or a failed attempt.
Declaration
public static Attempt<TResult, TStatus> If(bool condition, TStatus succStatus, TStatus failStatus)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
TStatus | succStatus | The status of the successful attempt. |
TStatus | failStatus | The status of the failed attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The attempt. |
If(Boolean, TStatus, TStatus, TResult)
Creates a successful or a failed attempt, with a result.
Declaration
public static Attempt<TResult, TStatus> If(bool condition, TStatus succStatus, TStatus failStatus, TResult result)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
TStatus | succStatus | The status of the successful attempt. |
TStatus | failStatus | The status of the failed attempt. |
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The attempt. |
Succeed(TStatus)
Creates a successful attempt.
Declaration
public static Attempt<TResult, TStatus> Succeed(TStatus status)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The successful attempt. |
Succeed(TStatus, TResult)
Creates a successful attempt with a result.
Declaration
public static Attempt<TResult, TStatus> Succeed(TStatus status, TResult result)
Parameters
Type | Name | Description |
---|---|---|
TStatus | status | The status of the attempt. |
TResult | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<TResult, TStatus> | The successful attempt. |
Operators
View SourceImplicit(Attempt<TResult, TStatus> 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, TStatus> a)
Parameters
Type | Name | Description |
---|---|---|
Attempt<TResult, TStatus> | a |
Returns
Type | Description |
---|---|
System.Boolean |