Skip to content

Fix BooleanToVisibilityConverter parameter handling to support both string and bool types#26

Merged
casuffitsharp merged 2 commits intochore/sq_issuesfrom
copilot/sub-pr-21
Mar 2, 2026
Merged

Fix BooleanToVisibilityConverter parameter handling to support both string and bool types#26
casuffitsharp merged 2 commits intochore/sq_issuesfrom
copilot/sub-pr-21

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

ConvertBack (and Convert) would throw InvalidCastException if ConverterParameter was passed as a bool instead of a string, and bool.Parse would throw FormatException on any invalid string value.

Changes

  • Extracted GetBoolParameter helper shared by both Convert and ConvertBack, eliminating duplicated parameter-parsing logic
  • Handles both bool and string parameter types via pattern matching — direct bool is returned as-is, strings go through bool.TryParse
  • null and invalid strings safely return false instead of throwing
private static bool GetBoolParameter(object parameter) =>
    parameter is bool b ? b : parameter is string s && bool.TryParse(s, out bool result) && result;

💡 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…nd bool

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on sonar refactor PR Fix BooleanToVisibilityConverter parameter handling to support both string and bool types Mar 2, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 2, 2026

@casuffitsharp casuffitsharp marked this pull request as ready for review March 2, 2026 04:29
@casuffitsharp casuffitsharp merged commit 5d8c05e into chore/sq_issues Mar 2, 2026
2 checks passed
@casuffitsharp casuffitsharp deleted the copilot/sub-pr-21 branch March 2, 2026 04:29
casuffitsharp added a commit that referenced this pull request Mar 2, 2026
…tring and bool types (#26)

* Initial plan

* Fix BooleanToVisibilityConverter to handle parameter as both string and bool

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>
casuffitsharp added a commit that referenced this pull request Mar 2, 2026
* refactor(sonar): addresses sonarqube issues

* [WIP] Update implementation based on feedback from sonar review (#24)

* Initial plan

* refactor: rename CPU.cs to Cpu.cs to match the Cpu type name

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

* Use pattern matching to eliminate NullReferenceException in OnSelectedProcessChanged (#23)

* Initial plan

* Use pattern matching instead of unsafe cast in OnSelectedProcessChanged

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

* Rename PCB.cs to Pcb.cs to match declared type name (#22)

* Initial plan

* Rename PCB.cs to Pcb.cs to match the Pcb class name

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* [WIP] Update PR to resolve SonarQube issues based on feedback (#25)

* Initial plan

* Fix ConvertBack to parse parameter as string instead of casting to bool

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

* Adjusted #pragma warning restore S2325 placement for clarity.

* Fix BooleanToVisibilityConverter parameter handling to support both string and bool types (#26)

* Initial plan

* Fix BooleanToVisibilityConverter to handle parameter as both string and bool

Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: casuffitsharp <78829483+casuffitsharp@users.noreply.github.com>

* Performing code cleanup

* Use null-conditional when updating prev process state

Replaced direct assignment with null-conditional operator for prev.State to prevent possible NullReferenceException if prev is null.

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants