Skip to content

[code-simplifier] Simplify BuildEvaluators with Array.ConvertAll method group#9100

Draft
Evangelink wants to merge 1 commit into
mainfrom
simplify/member-condition-guard-clauses-7c58f8035778946e
Draft

[code-simplifier] Simplify BuildEvaluators with Array.ConvertAll method group#9100
Evangelink wants to merge 1 commit into
mainfrom
simplify/member-condition-guard-clauses-7c58f8035778946e

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Code Simplification — 2026-06-13

This PR simplifies code introduced in #9071 (MemberConditionAttribute) to improve clarity and conciseness while preserving all functionality.

File Simplified

  • src/TestFramework/TestFramework/Attributes/TestMethod/MemberConditionAttribute.cs — Replace manual for-loop in BuildEvaluators with Array.ConvertAll + method group

Improvement Made

Replaced manual array-fill loop with Array.ConvertAll

The BuildEvaluators method allocated a new Func<bool>[], then filled it with a for-loop. Array.ConvertAll expresses the same intent in one line using a method group:

// Before (9 lines)
private Func<bool>[] BuildEvaluators()
{
    var evaluators = new Func<bool>[_conditionMemberNames.Length];
    for (int i = 0; i < _conditionMemberNames.Length; i++)
    {
        evaluators[i] = BuildEvaluator(_conditionMemberNames[i]);
    }
    return evaluators;
}

// After (2 lines)
private Func<bool>[] BuildEvaluators()
    => Array.ConvertAll(_conditionMemberNames, BuildEvaluator);

Array.ConvertAll is available on netstandard2.0, uses a method group instead of a lambda (avoids a delegate wrapper allocation), and makes the transform intent immediately clear.

Changes Based On

Recent changes from:

Testing

  • ✅ Build succeeds (dotnet build src/TestFramework/TestFramework/TestFramework.csproj)
  • ✅ No IDE0046 or other style-rule violations
  • ✅ No functional changes — behavior is identical (same array output, same exception paths)

Review Focus

Please verify:

  • Array.ConvertAll output is equivalent to the for-loop
  • Method group BuildEvaluator correctly binds to Func<bool> BuildEvaluator(string)
  • No unintended side effects

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Code Simplifier workflow. · 1.7K AIC · ⌖ 34 AIC · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/code-simplifier.md@main
  • expires on Jun 14, 2026, 2:05 PM UTC

…od group

Replace the manual for-loop in BuildEvaluators with Array.ConvertAll and
a method group reference to BuildEvaluator. Array.ConvertAll is available
on netstandard2.0+, avoids a separate array allocation followed by index
assignment, and expresses the intent (convert each element) more directly
than an explicit loop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 13, 2026 14:05
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/tech-debt Code health, refactoring, simplification. labels Jun 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a small refactor in the MSTest MemberConditionAttribute implementation (TestFramework) by simplifying BuildEvaluators() to use Array.ConvertAll, preserving the existing evaluator-building behavior while making the intent more direct.

Changes:

  • Replaced a manual array allocation + for loop in BuildEvaluators() with Array.ConvertAll(_conditionMemberNames, BuildEvaluator).
  • Preserved the same exception paths and per-member evaluator construction via the existing BuildEvaluator(string) method.
Show a summary per file
File Description
src/TestFramework/TestFramework/Attributes/TestMethod/MemberConditionAttribute.cs Simplifies BuildEvaluators() by converting member-name strings to evaluator delegates via Array.ConvertAll using a method group.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/automation Created or maintained by an agentic workflow. type/tech-debt Code health, refactoring, simplification.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants