Struct Attempt<T>
Represents the result of an operation attempt.
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
[Serializable]
public struct Attempt<T>
Type Parameters
Name | Description |
---|---|
T | The type of the attempted operation result. |
Constructors
Attempt(Boolean, T)
Initialize a new instance of the Attempt<T> struct with a result.
Declaration
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succeed(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
public Attempt(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. |
Remarks
Keep it for backward compatibility sake.
Attempt(Exception)
Initialize a new instance of the Attempt<T> struct representing a failed attempt, with an exception.
Declaration
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succeed(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
public Attempt(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | exception | The exception causing the failure of the attempt. |
Remarks
Keep it for backward compatibility sake.
Fields
False
Represents an unsuccessful attempt.
Declaration
[Obsolete(".Failed is obsolete, you should use Attempt<T>.Fail() instead.", false)]
public static readonly Attempt<T> False
Field Value
Type | Description |
---|---|
Attempt<T> |
Remarks
Keep it for backward compatibility sake.
Properties
Error
Gets the exception associated with an unsuccessful attempt.
Declaration
[Obsolete(".Error is obsolete, you should use .Exception instead.", false)]
public Exception Error { get; }
Property Value
Type | Description |
---|---|
System.Exception |
Remarks
Keep it for backward compatibility sake.
Exception
Gets the exception associated with an unsuccessful attempt.
Declaration
public Exception Exception { get; }
Property Value
Type | Description |
---|---|
System.Exception |
Result
Gets the attempt result.
Declaration
public T Result { get; }
Property Value
Type | Description |
---|---|
T |
Success
Gets a value indicating whether this Attempt<T> was successful.
Declaration
public bool Success { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
Fail()
Creates a failed attempt.
Declaration
public static Attempt<T> Fail()
Returns
Type | Description |
---|---|
Attempt<T> | The failed attempt. |
Fail(T)
Creates a failed attempt with a result.
Declaration
public static Attempt<T> Fail(T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The failed attempt. |
Fail(T, Exception)
Creates a failed attempt with a result and an exception.
Declaration
public static Attempt<T> Fail(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. |
Fail(Exception)
Creates a failed attempt with an exception.
Declaration
public static Attempt<T> Fail(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | exception | The exception causing the failure of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The failed attempt. |
Succeed()
Creates a successful attempt.
Declaration
public static Attempt<T> Succeed()
Returns
Type | Description |
---|---|
Attempt<T> | The successful attempt. |
Succeed(T)
Creates a successful attempt with a result.
Declaration
public static Attempt<T> Succeed(T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The successful attempt. |
SucceedIf(Boolean)
Creates a successful or a failed attempt.
Declaration
public static Attempt<T> SucceedIf(bool condition)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
Returns
Type | Description |
---|---|
Attempt<T> | The attempt. |
SucceedIf(Boolean, T)
Creates a successful or a failed attempt, with a result.
Declaration
public static Attempt<T> SucceedIf(bool condition, T result)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | condition | A value indicating whether the attempt is successful. |
T | result | The result of the attempt. |
Returns
Type | Description |
---|---|
Attempt<T> | The attempt. |
Operators
Implicit(Attempt<T> to Boolean)
Implicity operator to check if the attempt was successful without having to access the 'success' property
Declaration
public static implicit operator bool (Attempt<T> a)
Parameters
Type | Name | Description |
---|---|---|
Attempt<T> | a |
Returns
Type | Description |
---|---|
System.Boolean |