SEBWIN-219: Used awesome new C# language feature for type checks.

This commit is contained in:
dbuechel 2018-02-19 14:36:00 +01:00
parent 24c5ea3ba9
commit ea97930033
10 changed files with 40 additions and 40 deletions

View file

@ -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
{

View file

@ -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()}!");

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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();
}
}
}

View file

@ -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()}!");

View file

@ -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
{

View file

@ -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();

View file

@ -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();
}
}
}

View file

@ -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
{