From 2af97e5a7fdee8c0452e78eb9b3bb59bada2e866 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 19:28:59 +0000 Subject: [PATCH] Inline ValidateTargets into call sites Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/cb9a6a6a-02c7-41a8-a4b4-da16ad62ef86 Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../WorkflowBuilderExtensions.cs | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs index 86699f4683..ae5625edcb 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs @@ -57,9 +57,18 @@ public static class WorkflowBuilderExtensions { Throw.IfNull(builder); Throw.IfNull(source); + Throw.IfNull(targets); Func predicate = WorkflowBuilder.CreateConditionFunc(IsAllowedTypeAndMatchingCondition)!; - List targetList = ValidateTargets(targets); + List targetList = new(); + foreach (ExecutorBinding target in targets) + { + Throw.IfNull(target, nameof(targets)); + + targetList.Add(target); + } + + Throw.IfNullOrEmpty(targetList, nameof(targets)); if (targetList.Count == 1) { @@ -100,9 +109,18 @@ public static class WorkflowBuilderExtensions { Throw.IfNull(builder); Throw.IfNull(source); + Throw.IfNull(targets); Func predicate = WorkflowBuilder.CreateConditionFunc((Func)IsAllowedType)!; - List targetList = ValidateTargets(targets); + List targetList = new(); + foreach (ExecutorBinding target in targets) + { + Throw.IfNull(target, nameof(targets)); + + targetList.Add(target); + } + + Throw.IfNullOrEmpty(targetList, nameof(targets)); if (targetList.Count == 1) { @@ -116,29 +134,6 @@ public static class WorkflowBuilderExtensions static bool IsAllowedType(object? message) => message is null; } - /// - /// Validates a target collection and returns it as a list. - /// - /// The target executor bindings to validate. - /// A validated list of target executor bindings. - /// Thrown when is null or contains a null element. - /// Thrown when is empty. - private static List ValidateTargets(IEnumerable targets) - { - Throw.IfNull(targets); - - List targetList = new(); - foreach (ExecutorBinding target in targets) - { - Throw.IfNull(target, nameof(targets)); - - targetList.Add(target); - } - - Throw.IfNullOrEmpty(targetList, nameof(targets)); - return targetList; - } - /// /// Adds a sequential chain of executors to the workflow, connecting each executor in order so that each is /// executed after the previous one.