diff --git a/SafeExamBrowser.Core/Communication/BaseHost.cs b/SafeExamBrowser.Core/Communication/BaseHost.cs index 338df6e5..1e9136b3 100644 --- a/SafeExamBrowser.Core/Communication/BaseHost.cs +++ b/SafeExamBrowser.Core/Communication/BaseHost.cs @@ -103,9 +103,9 @@ namespace SafeExamBrowser.Core.Communication if (IsAuthorized(message?.CommunicationToken)) { - if (message is SimpleMessage) + if (message is SimpleMessage simpleMessage) { - response = OnReceive((message as SimpleMessage).Purport); + response = OnReceive(simpleMessage.Purport); } else { diff --git a/SafeExamBrowser.Core/Logging/DefaultLogFormatter.cs b/SafeExamBrowser.Core/Logging/DefaultLogFormatter.cs index 310bae5e..2b88ec2d 100644 --- a/SafeExamBrowser.Core/Logging/DefaultLogFormatter.cs +++ b/SafeExamBrowser.Core/Logging/DefaultLogFormatter.cs @@ -15,14 +15,14 @@ namespace SafeExamBrowser.Core.Logging { public string Format(ILogContent content) { - if (content is ILogText) + if (content is ILogText text) { - return (content as ILogText).Text; + return text.Text; } - if (content is ILogMessage) + if (content is ILogMessage message) { - return FormatLogMessage(content as ILogMessage); + return FormatLogMessage(message); } throw new NotImplementedException($"The default formatter is not yet implemented for log content of type {content.GetType()}!"); diff --git a/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs index 9084889a..c818243c 100644 --- a/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs @@ -93,9 +93,9 @@ namespace SafeExamBrowser.UserInterface.Classic private void InitializeBrowserWindow(IBrowserControl browserControl) { - if (browserControl is System.Windows.Forms.Control) + if (browserControl is System.Windows.Forms.Control control) { - BrowserControlHost.Child = browserControl as System.Windows.Forms.Control; + BrowserControlHost.Child = control; } Closing += (o, args) => closing?.Invoke(); diff --git a/SafeExamBrowser.UserInterface.Classic/Controls/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Classic/Controls/KeyboardLayoutControl.xaml.cs index 76f00cf6..f6f31466 100644 --- a/SafeExamBrowser.UserInterface.Classic/Controls/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/Controls/KeyboardLayoutControl.xaml.cs @@ -83,9 +83,9 @@ namespace SafeExamBrowser.UserInterface.Classic.Controls foreach (var child in LayoutsStackPanel.Children) { - if (child is KeyboardLayoutButton) + if (child is KeyboardLayoutButton keyboardLayoutButton) { - (child as KeyboardLayoutButton).IsCurrent = false; + keyboardLayoutButton.IsCurrent = false; } } diff --git a/SafeExamBrowser.UserInterface.Classic/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface.Classic/Taskbar.xaml.cs index f2734fd7..81f92ddd 100644 --- a/SafeExamBrowser.UserInterface.Classic/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/Taskbar.xaml.cs @@ -29,25 +29,25 @@ namespace SafeExamBrowser.UserInterface.Classic public void AddApplication(IApplicationButton button) { - if (button is UIElement) + if (button is UIElement uiElement) { - ApplicationStackPanel.Children.Add(button as UIElement); + ApplicationStackPanel.Children.Add(uiElement); } } public void AddNotification(INotificationButton button) { - if (button is UIElement) + if (button is UIElement uiElement) { - NotificationStackPanel.Children.Add(button as UIElement); + NotificationStackPanel.Children.Add(uiElement); } } public void AddSystemControl(ISystemControl control) { - if (control is UIElement) + if (control is UIElement uiElement) { - SystemControlStackPanel.Children.Add(control as UIElement); + SystemControlStackPanel.Children.Add(uiElement); } } @@ -82,9 +82,9 @@ namespace SafeExamBrowser.UserInterface.Classic { foreach (var child in SystemControlStackPanel.Children) { - if (child is ISystemControl) + if (child is ISystemControl systemControl) { - (child as ISystemControl).Close(); + systemControl.Close(); } } } diff --git a/SafeExamBrowser.UserInterface.Classic/Utilities/RuntimeWindowLogFormatter.cs b/SafeExamBrowser.UserInterface.Classic/Utilities/RuntimeWindowLogFormatter.cs index d7c49d06..b8c9c605 100644 --- a/SafeExamBrowser.UserInterface.Classic/Utilities/RuntimeWindowLogFormatter.cs +++ b/SafeExamBrowser.UserInterface.Classic/Utilities/RuntimeWindowLogFormatter.cs @@ -15,14 +15,14 @@ namespace SafeExamBrowser.UserInterface.Classic.Utilities { public string Format(ILogContent content) { - if (content is ILogText) + if (content is ILogText text) { - return (content as ILogText).Text; + return text.Text; } - if (content is ILogMessage) + if (content is ILogMessage message) { - return FormatLogMessage(content as ILogMessage); + return FormatLogMessage(message); } throw new NotImplementedException($"The runtime window formatter is not yet implemented for log content of type {content.GetType()}!"); diff --git a/SafeExamBrowser.UserInterface.Classic/ViewModels/LogViewModel.cs b/SafeExamBrowser.UserInterface.Classic/ViewModels/LogViewModel.cs index 5cf28944..1c2761c3 100644 --- a/SafeExamBrowser.UserInterface.Classic/ViewModels/LogViewModel.cs +++ b/SafeExamBrowser.UserInterface.Classic/ViewModels/LogViewModel.cs @@ -33,13 +33,13 @@ namespace SafeExamBrowser.UserInterface.Classic.ViewModels public void Notify(ILogContent content) { - if (content is ILogText) + if (content is ILogText text) { - AppendLogText(content as ILogText); + AppendLogText(text); } - else if (content is ILogMessage) + else if (content is ILogMessage message) { - AppendLogMessage(content as ILogMessage); + AppendLogMessage(message); } else { diff --git a/SafeExamBrowser.UserInterface.Windows10/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Windows10/BrowserWindow.xaml.cs index 29d7ca44..3401513d 100644 --- a/SafeExamBrowser.UserInterface.Windows10/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Windows10/BrowserWindow.xaml.cs @@ -91,9 +91,9 @@ namespace SafeExamBrowser.UserInterface.Windows10 private void InitializeBrowserWindow(IBrowserControl browserControl) { - if (browserControl is System.Windows.Forms.Control) + if (browserControl is System.Windows.Forms.Control control) { - BrowserControlHost.Child = browserControl as System.Windows.Forms.Control; + BrowserControlHost.Child = control; } Closing += (o, args) => closing?.Invoke(); diff --git a/SafeExamBrowser.UserInterface.Windows10/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface.Windows10/Taskbar.xaml.cs index d2a7b975..dcf739b4 100644 --- a/SafeExamBrowser.UserInterface.Windows10/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface.Windows10/Taskbar.xaml.cs @@ -29,25 +29,25 @@ namespace SafeExamBrowser.UserInterface.Windows10 public void AddApplication(IApplicationButton button) { - if (button is UIElement) + if (button is UIElement uiElement) { - ApplicationStackPanel.Children.Add(button as UIElement); + ApplicationStackPanel.Children.Add(uiElement); } } public void AddNotification(INotificationButton button) { - if (button is UIElement) + if (button is UIElement uiElement) { - NotificationStackPanel.Children.Add(button as UIElement); + NotificationStackPanel.Children.Add(uiElement); } } public void AddSystemControl(ISystemControl control) { - if (control is UIElement) + if (control is UIElement uiElement) { - SystemControlStackPanel.Children.Add(control as UIElement); + SystemControlStackPanel.Children.Add(uiElement); } } @@ -82,9 +82,9 @@ namespace SafeExamBrowser.UserInterface.Windows10 { foreach (var child in SystemControlStackPanel.Children) { - if (child is ISystemControl) + if (child is ISystemControl systemControl) { - (child as ISystemControl).Close(); + systemControl.Close(); } } } diff --git a/SafeExamBrowser.UserInterface.Windows10/ViewModels/LogViewModel.cs b/SafeExamBrowser.UserInterface.Windows10/ViewModels/LogViewModel.cs index dbac4603..e012152f 100644 --- a/SafeExamBrowser.UserInterface.Windows10/ViewModels/LogViewModel.cs +++ b/SafeExamBrowser.UserInterface.Windows10/ViewModels/LogViewModel.cs @@ -33,13 +33,13 @@ namespace SafeExamBrowser.UserInterface.Windows10.ViewModels public void Notify(ILogContent content) { - if (content is ILogText) + if (content is ILogText text) { - AppendLogText(content as ILogText); + AppendLogText(text); } - else if (content is ILogMessage) + else if (content is ILogMessage message) { - AppendLogMessage(content as ILogMessage); + AppendLogMessage(message); } else {