From be3a6a7efaf8e45c128447f80ec70db400551c08 Mon Sep 17 00:00:00 2001 From: Konstantin Semenenko Date: Fri, 14 Jun 2024 11:32:28 +0200 Subject: [PATCH] Result.From(bool) --- Directory.Build.props | 4 ++-- .../Result/Result.From.cs | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7673105..ca4b537 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -24,8 +24,8 @@ https://github.com/managedcode/Communication https://github.com/managedcode/Communication Managed Code - Communication - 8.0.2 - 8.0.2 + 8.0.3 + 8.0.3 diff --git a/ManagedCode.Communication/Result/Result.From.cs b/ManagedCode.Communication/Result/Result.From.cs index 67d016a..ad5b61d 100644 --- a/ManagedCode.Communication/Result/Result.From.cs +++ b/ManagedCode.Communication/Result/Result.From.cs @@ -110,4 +110,24 @@ public static async Task From(Func valueTask) return Fail(Error.FromException(e)); } } + + public static Result From(bool condition) + { + return condition ? Succeed() : Fail(); + } + + public static Result From(bool condition, Error error) + { + return condition ? Succeed() : Fail(error); + } + + public static Result From(Func condition) + { + return condition() ? Succeed() : Fail(); + } + + public static Result From(Func condition, Error error) + { + return condition() ? Succeed() : Fail(error); + } } \ No newline at end of file