Skip to content

[Code Quality] Manager MainWindow.xaml.cs — Type pattern variable shadows type name in GetPerformanceVm/GetConsoleVm #706

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

File: src/Servy.Manager/Views/MainWindow.xaml.cs, lines 259 and 268

GetPerformanceVm() and GetConsoleVm() declare type pattern variables whose names match the type exactly (PerformanceView PerformanceView, ConsoleView ConsoleView). This is valid C# but hurts readability and shadows the type identifier within the expression:

        private PerformanceViewModel? GetPerformanceVm()
            => PerformanceTab.Content is PerformanceView PerformanceView ? PerformanceView.DataContext as PerformanceViewModel : null;

        private ConsoleViewModel? GetConsoleVm()
            => ConsoleTab.Content is ConsoleView ConsoleView ? ConsoleView.DataContext as ConsoleViewModel : null;

The sibling methods GetLogsVm (line 288) use a lowercase logsView which reads cleanly — these two are inconsistent with the rest of the file.

Suggested fix

Use a distinct lowercase name for the pattern variable:

        private PerformanceViewModel? GetPerformanceVm()
            => PerformanceTab.Content is PerformanceView perfView ? perfView.DataContext as PerformanceViewModel : null;

        private ConsoleViewModel? GetConsoleVm()
            => ConsoleTab.Content is ConsoleView consoleView ? consoleView.DataContext as ConsoleViewModel : null;

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions