From 1afc95f9c626502aafa6187b3b8dae47efbfb965 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 30 Jan 2026 14:24:57 +0100 Subject: [PATCH] Add obsolete FirstAsync extension to TaskExtensions Added FirstAsync as an obsolete extension method for Task>. This method returns the first element or throws a custom exception if the result is null, using a provided factory delegate. Intended for legacy .NET projects. --- .../Common/Extensions/TaskExtensions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EnvelopeGenerator.Application/Common/Extensions/TaskExtensions.cs b/EnvelopeGenerator.Application/Common/Extensions/TaskExtensions.cs index 7360675c..2fae57ea 100644 --- a/EnvelopeGenerator.Application/Common/Extensions/TaskExtensions.cs +++ b/EnvelopeGenerator.Application/Common/Extensions/TaskExtensions.cs @@ -65,6 +65,19 @@ public static class TaskExtensions /// [Obsolete("Implement Mediator behaviors in the Osolete .NET project.")] public static Task FirstOrDefaultAsync(this Task> task) => task.Then(t => t.FirstOrDefault()); + + /// + /// + /// + /// + /// + /// + /// + /// + [Obsolete("Implement Mediator behaviors in the Osolete .NET project.")] + public static Task FirstAsync(this Task> task, Func factory) + where TException : Exception + => task.Then(t => t.FirstOrDefault()) ?? throw factory(); } ///