Class Attempt
Provides ways to create attempts.
Inheritance
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
public static class Attempt
Methods
Fail<T>(T)
Creates a failed attempt with a result.
Declaration
public static Attempt<T> Fail<T>(T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The failed attempt. |
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
Fail<T>(T, Exception)
Creates a failed attempt with a result and an exception.
Declaration
public static Attempt<T> Fail<T>(T result, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
T | result | The result of the attempt. |
System.Exception | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The failed attempt. |
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
If<T>(Boolean, T)
Creates a successful or a failed attempt, with a result.
Declaration
public static Attempt<T> If<T>(bool success, T result)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | success | A value indicating whether the attempt is successful. |
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The attempt. |
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
Succeed<T>(T)
Creates a successful attempt with a result.
Declaration
public static Attempt<T> Succeed<T>(T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The successful attempt. |
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
Try<T>(Attempt<T>, Action<T>, Action<Exception>)
Executes an attempt function, with callbacks.
Declaration
public static Attempt.Outcome Try<T>(Attempt<T> attempt, Action<T> onSuccess, Action<Exception> onFail = null)
Parameters
Type | Name | Description |
---|---|---|
Attempt<T> | attempt | The attempt returned by the attempt function. |
System.Action<T> | onSuccess | An action to execute in case the attempt succeeds. |
System.Action<System.Exception> | onFail | An action to execute in case the attempt fails. |
Returns
Type | Description |
---|---|
Attempt.Outcome | The outcome of the attempt. |
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
Remarks
Runs onSuccess or onFail depending on the whether the attempt function reports a success or a failure.