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.