Skip to content

[code-simplifier] Simplify nested ternary in TestingPlatformResourceDetector.GetOsType - #11531

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
code-simplifier/opentelemetry-resource-detector-20260925-dba095365f1c6d40
Sep 25, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
code-simplifier/opentelemetry-resource-detector-20260925-dba095365f1c6d40

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Replace the chained nested ternary expression with a switch expression on a boolean discriminator, avoiding the nested-ternary anti-pattern while preserving IDE0046's preference for expression-bodied returns and identical runtime behavior.

Fixes #11530

Replace the chained nested ternary expression with a switch expression
on a boolean discriminator, avoiding the nested-ternary anti-pattern
while preserving IDE0046's preference for expression-bodied returns
and identical runtime behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 25, 2026 15:51
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 25, 2026

@github-actions github-actions Bot 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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review outcome: No blocking findings; one nit questioning whether the ternary→true switch refactor is a genuine readability improvement.

Change classification

  • Microsoft.Testing.Extensions.OpenTelemetry (internal, non-public API): TestingPlatformResourceDetector.GetOsType() rewritten from a chained ternary to a true switch { _ when ... } expression; behaviorally identical.

Confidence at a glance

🟡 Code style & idiom quality — refactor is behavior-preserving but debatable as a net improvement
  • Why it applies: The change swaps one control-flow expression form for another with no functional difference, directly implicating the repo's "use pattern matching/switch expressions" style guidance.
  • Evidence: See inline comment on the changed hunk — true switch { _ when ... } has no real discriminant subject, unlike the genuine switch-on-value pattern used a few lines later in GetHostArchitecture().
  • Gap or disposition: Not a correctness issue; purely a style judgment call.
  • Action: Optional — consider reverting to the ternary or using a lookup-table-based switch with a real subject if maintainers agree the current form isn't clearer.

⚪ Not applicable: correctness, public API, backward compatibility, performance, cross-TFM, IPC, localization, security, tests, build/dependencies (single internal method, no behavior change, no new dependencies).

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 25, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 25, 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.

Copilot review overview

🟢 Approval recommended

The focused refactor preserves existing behavior and follows repository conventions.

Review effort: Balanced
Findings: None

What changed in this PR

Simplifies OpenTelemetry OS detection while preserving evaluation order and output.

Changes:

  • Replaces nested ternaries with a guarded switch expression.
  • Retains existing Windows, macOS, Linux, and fallback mappings.
File Description
TestingPlatformResourceDetector.cs Simplifies GetOsType() without behavioral changes.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 25, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Sep 25, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit 7cf3e50 into main Sep 25, 2026
28 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the code-simplifier/opentelemetry-resource-detector-20260925-dba095365f1c6d40 branch September 25, 2026 19:04
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the state/approved Proposal approved; ready for implementation. label Sep 25, 2026
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.

[code-simplifier] Simplify nested ternary in TestingPlatformResourceDetector.GetOsType

3 participants