Skip to content

Refactor foreach loops to use explicit .Where() filtering in ScriptGenerator#1899

Merged
danielmarbach merged 2 commits intoscript-builder-loadingfrom
copilot/sub-pr-1898
Jan 12, 2026
Merged

Refactor foreach loops to use explicit .Where() filtering in ScriptGenerator#1899
danielmarbach merged 2 commits intoscript-builder-loadingfrom
copilot/sub-pr-1898

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Code review feedback identified three foreach loops in ScriptGenerator.cs that implicitly filtered their target sequences using nested if statements. This PR refactors them to use explicit .Where() clauses.

Changes

  • CollectAssemblyFiles method: Refactored three foreach loops to use LINQ .Where() filtering:
    • RuntimeEnvironment DLL files enumeration
    • Assembly folder DLL files enumeration
    • Reference paths enumeration

Before/After

// Before
foreach (var file in Directory.GetFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll"))
{
    if (seen.Add(Path.GetFileName(file)))
    {
        yield return file;
    }
}

// After
foreach (var file in Directory.GetFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll").Where(f => seen.Add(Path.GetFileName(f))))
{
    yield return file;
}

The refactoring makes filtering intent explicit while preserving identical behavior and lazy evaluation semantics.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 12, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build src/ScriptBuilder/ScriptBuilder.csproj (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build src/ScriptBuilder/ScriptBuilder.csproj --no-restore (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix unhandled exception for missing assembly in SqlPersistenceTask Refactor foreach loops to use explicit .Where() filtering in ScriptGenerator Jan 12, 2026
Copilot AI requested a review from danielmarbach January 12, 2026 11:20
@danielmarbach danielmarbach marked this pull request as ready for review January 12, 2026 11:28
@danielmarbach
Copy link
Contributor

Given that we already use Linq in this class I think that is fine

@danielmarbach danielmarbach merged commit 53a5e83 into script-builder-loading Jan 12, 2026
10 checks passed
@danielmarbach danielmarbach deleted the copilot/sub-pr-1898 branch January 12, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants