using System;
namespace Umbraco.Core
{
///
/// Provides ways to create attempts.
///
public static class Attempt
{
// note:
// cannot rely on overloads only to differenciate between with/without status
// in some cases it will always be ambiguous, so be explicit w/ 'WithStatus' methods
///
/// Creates a successful attempt with a result.
///
/// The type of the attempted operation result.
/// The result of the attempt.
/// The successful attempt.
public static Attempt Succeed(TResult result)
{
return Attempt.Succeed(result);
}
///
/// Creates a successful attempt with a result and a status.
///
/// The type of the attempted operation result.
/// The type of the attempted operation status.
/// The status of the attempt.
/// The result of the attempt.
/// The successful attempt.
public static Attempt SucceedWithStatus(TStatus status, TResult result)
{
return Attempt.Succeed(status, result);
}
///
/// Creates a failed attempt.
///
/// The type of the attempted operation result.
/// The failed attempt.
public static Attempt Fail()
{
return Attempt.Fail();
}
///
/// Creates a failed attempt with a result.
///
/// The type of the attempted operation result.
/// The result of the attempt.
/// The failed attempt.
public static Attempt Fail(TResult result)
{
return Attempt.Fail(result);
}
///
/// Creates a failed attempt with a result and a status.
///
/// The type of the attempted operation result.
/// The type of the attempted operation status.
/// The status of the attempt.
/// The result of the attempt.
/// The failed attempt.
public static Attempt FailWithStatus(TStatus status, TResult result)
{
return Attempt.Fail(status, result);
}
///
/// Creates a failed attempt with a result and an exception.
///
/// The type of the attempted operation result.
/// The result of the attempt.
/// The exception causing the failure of the attempt.
/// The failed attempt.
public static Attempt Fail(TResult result, Exception exception)
{
return Attempt.Fail(result, exception);
}
///
/// Creates a failed attempt with a result, an exception and a status.
///
/// The type of the attempted operation result.
/// The type of the attempted operation status.
/// The status of the attempt.
/// The result of the attempt.
/// The exception causing the failure of the attempt.
/// The failed attempt.
public static Attempt FailWithStatus(TStatus status, TResult result, Exception exception)
{
return Attempt.Fail(status, result, exception);
}
///
/// Creates a successful or a failed attempt, with a result.
///
/// The type of the attempted operation result.
/// A value indicating whether the attempt is successful.
/// The result of the attempt.
/// The attempt.
public static Attempt If(bool condition, TResult result)
{
return Attempt.If(condition, result);
}
///
/// Creates a successful or a failed attempt, with a result.
///
/// The type of the attempted operation result.
/// The type of the attempted operation status.
/// A value indicating whether the attempt is successful.
/// The status of the successful attempt.
/// The status of the failed attempt.
/// The result of the attempt.
/// The attempt.
public static Attempt IfWithStatus(bool condition, TStatus succStatus, TStatus failStatus, TResult result)
{
return Attempt.If(condition, succStatus, failStatus, result);
}
}
}