Files
Umbraco-CMS/src/Umbraco.Core/Attempt.cs
Mole bf41c2eeaa Netcore: Align namespaces (#9801)
* Rename Umbraco.Core namespace to Umbraco.Cms.Core

* Move extension methods in core project to Umbraco.Extensions

* Move extension methods in core project to Umbraco.Extensions

* Rename Umbraco.Examine namespace to Umbraco.Cms.Examine

* Move examine extensions to Umbraco.Extensions namespace

* Reflect changed namespaces in Builder and fix unit tests

* Adjust namespace in Umbraco.ModelsBuilder.Embedded

* Adjust namespace in Umbraco.Persistence.SqlCe

* Adjust namespace in Umbraco.PublishedCache.NuCache

* Align namespaces in Umbraco.Web.BackOffice

* Align namespaces in Umbraco.Web.Common

* Ensure that SqlCeSupport is still enabled after changing the namespace

* Align namespaces in Umbraco.Web.Website

* Align namespaces in Umbraco.Web.UI.NetCore

* Align namespaces in Umbraco.Tests.Common

* Align namespaces in Umbraco.Tests.UnitTests

* Align namespaces in Umbraco.Tests.Integration

* Fix errors caused by changed namespaces

* Fix integration tests

* Undo the Umbraco.Examine.Lucene namespace change

This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows.

* Fix merge

* Fix Merge
2021-02-18 11:06:02 +01:00

127 lines
5.8 KiB
C#

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