feat: Neue Erweiterungsmethoden zum Verarbeiten von Ergebnissen hinzufügen

- `HasAnyFlag` Methode hinzugefügt, um zu überprüfen, ob eine Benachrichtigung eines der angegebenen Flags hat.
- `Then` und `ThenAsync` Methoden für `Task<DataResult<T>>` Typ hinzugefügt, um asynchrone Ergebnisse basierend auf Erfolg oder Misserfolg zu verarbeiten.
This commit is contained in:
Developer 02
2024-09-16 10:08:11 +02:00
parent 96d03a5f59
commit a01e6e5b16
2 changed files with 31 additions and 2 deletions

View File

@@ -147,6 +147,35 @@ namespace DigitalData.Core.DTO
/// <returns>True if any notice has any of the specified flags; otherwise, false.</returns>
public static bool HasAnyFlag(this IEnumerable<Notice> notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f));
/// <summary>
/// Executes a function based on the success or failure of the task result,
/// without using result data.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a result to evaluate.</param>
/// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static I? Then<I>(this Result result, Func<I> Success)
{
return result.IsSuccess ? Success() : default;
}
/// <summary>
/// Executes a function based on the success or failure of the task result,
/// using the data in the result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a data result to evaluate.</param>
/// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I?> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync)
{
return result.IsSuccess ? await SuccessAsync() : default;
}
/// <summary>
/// Executes a function based on the success or failure of the result.
/// </summary>

View File

@@ -35,8 +35,8 @@ Global
{DB404CD9-CBB8-4771-AB1B-FD4FDE2C28CC}.Debug|Any CPU.Build.0 = Release|Any CPU
{DB404CD9-CBB8-4771-AB1B-FD4FDE2C28CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB404CD9-CBB8-4771-AB1B-FD4FDE2C28CC}.Release|Any CPU.Build.0 = Release|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Debug|Any CPU.Build.0 = Release|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C57B2480-F632-4691-9C4C-8CC01237203C}.Release|Any CPU.Build.0 = Release|Any CPU
{B54DEF90-C30C-44EA-9875-76F1B330CBB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU