diff --git a/DigitalData.Core.DTO/DTOExtensions.cs b/DigitalData.Core.DTO/DTOExtensions.cs index 3940517..c5bee5c 100644 --- a/DigitalData.Core.DTO/DTOExtensions.cs +++ b/DigitalData.Core.DTO/DTOExtensions.cs @@ -147,6 +147,35 @@ namespace DigitalData.Core.DTO /// True if any notice has any of the specified flags; otherwise, false. public static bool HasAnyFlag(this IEnumerable notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f)); + /// + /// Executes a function based on the success or failure of the task result, + /// without using result data. + /// + /// The type of the return value. + /// The task returning a result to evaluate. + /// The function to execute if the result is successful. + /// The function to execute if the result is a failure. + /// The result of the executed function. + public static I? Then(this Result result, Func Success) + { + return result.IsSuccess ? Success() : default; + } + + /// + /// Executes a function based on the success or failure of the task result, + /// using the data in the result. + /// + /// The type of the data in the result. + /// The type of the return value. + /// The task returning a data result to evaluate. + /// The function to execute if the data result is successful. + /// The function to execute if the data result is a failure. + /// The result of the executed function. + public static async Task ThenAsync(this Result result, Func> SuccessAsync) + { + return result.IsSuccess ? await SuccessAsync() : default; + } + /// /// Executes a function based on the success or failure of the result. /// diff --git a/DigitalData.Core.sln b/DigitalData.Core.sln index e8314a3..addac09 100644 --- a/DigitalData.Core.sln +++ b/DigitalData.Core.sln @@ -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