Skip to content

Commit d942a17

Browse files
ooplesclaude
andcommitted
fix: replace validate foreach with linq all in prompttemplatebase
Changed foreach loop with early return pattern to LINQ All method for cleaner declarative validation of required variables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 766447c commit d942a17

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

src/PromptEngineering/Templates/PromptTemplateBase.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,9 @@ public virtual bool Validate(Dictionary<string, string> variables)
9696
return false;
9797
}
9898

99-
// Check that all required variables are present and not null
100-
foreach (var variable in InputVariables)
101-
{
102-
if (!variables.TryGetValue(variable, out var value) || value == null)
103-
{
104-
return false;
105-
}
106-
}
107-
108-
return true;
99+
// Check that all required variables are present and not null using LINQ
100+
return InputVariables.All(variable =>
101+
variables.TryGetValue(variable, out var value) && value != null);
109102
}
110103

111104
/// <summary>

0 commit comments

Comments
 (0)