Repository navigation
[code-simplifier] Simplify nested ternary in TestingPlatformResourceDetector.GetOsType - #11531
Conversation
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>
There was a problem hiding this comment.
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 atrue 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 inGetHostArchitecture(). - 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).
There was a problem hiding this comment.
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.
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