From 9a7ee0545adaabeea206ff6c5aff69532cd39401 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 30 Jan 2020 22:50:14 +0000 Subject: [PATCH] Refactor delegate types to lambda expressions (#11690) --- .../ManagementList/Innerlist.cs | 4 +-- .../commandHelpers/HelpWindowHelper.cs | 4 +-- .../commandHelpers/OutGridView.cs | 30 +++++++++---------- .../commandHelpers/ShowCommandHelper.cs | 19 +++++------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/Innerlist.cs b/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/Innerlist.cs index 4f04b09d7a..28f8be37a4 100644 --- a/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/Innerlist.cs +++ b/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/Innerlist.cs @@ -146,7 +146,7 @@ namespace Microsoft.Management.UI.Internal { Dispatcher.BeginInvoke( DispatcherPriority.Background, - (DispatcherOperationCallback)delegate(object arg) + (DispatcherOperationCallback)((arg) => { if (this.IsLoaded) { @@ -154,7 +154,7 @@ namespace Microsoft.Management.UI.Internal } return null; - }, + }), item); } diff --git a/src/Microsoft.Management.UI.Internal/commandHelpers/HelpWindowHelper.cs b/src/Microsoft.Management.UI.Internal/commandHelpers/HelpWindowHelper.cs index 4c47395c8f..04e6d74ae6 100644 --- a/src/Microsoft.Management.UI.Internal/commandHelpers/HelpWindowHelper.cs +++ b/src/Microsoft.Management.UI.Internal/commandHelpers/HelpWindowHelper.cs @@ -30,13 +30,13 @@ namespace Microsoft.PowerShell.Commands.Internal { ownerWindow.Dispatcher.Invoke( new SendOrPostCallback( - delegate(object ignored) + (_) => { HelpWindow helpWindow = new HelpWindow(helpObj); helpWindow.Owner = ownerWindow; helpWindow.Show(); - helpWindow.Closed += new EventHandler(delegate(object sender, EventArgs e) { ownerWindow.Focus(); }); + helpWindow.Closed += new EventHandler((sender, e) => ownerWindow.Focus()); }), string.Empty); return; diff --git a/src/Microsoft.Management.UI.Internal/commandHelpers/OutGridView.cs b/src/Microsoft.Management.UI.Internal/commandHelpers/OutGridView.cs index 8e157d2660..ea36be8c73 100644 --- a/src/Microsoft.Management.UI.Internal/commandHelpers/OutGridView.cs +++ b/src/Microsoft.Management.UI.Internal/commandHelpers/OutGridView.cs @@ -409,7 +409,7 @@ namespace Microsoft.Management.UI.Internal this.managementList.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( - delegate() + () => { // Pick the length of the shortest incoming arrays. Normally all incoming arrays should be of the same length. int length = propertyNames.Length; @@ -461,19 +461,19 @@ namespace Microsoft.Management.UI.Internal // Set focus on ListView this.managementList.List.SelectedIndex = 0; this.managementList.List.Focus(); - } - catch (Exception e) - { - // Store the exception in a local variable that will be checked later. - if (e.InnerException != null) - { - this.exception = e.InnerException; - } - else - { - this.exception = e; - } - } + } + catch (Exception e) + { + // Store the exception in a local variable that will be checked later. + if (e.InnerException != null) + { + this.exception = e.InnerException; + } + else + { + this.exception = e; + } + } })); } @@ -492,7 +492,7 @@ namespace Microsoft.Management.UI.Internal this.managementList.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( - delegate() + () => { try { diff --git a/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs b/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs index b23cf686d2..95925ff40d 100644 --- a/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs +++ b/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs @@ -645,7 +645,7 @@ Function PSGetSerializedShowCommandInfo } ModuleViewModel moduleToSelect = returnValue.Modules.Find( - new Predicate(delegate(ModuleViewModel module) + new Predicate((module) => { return module.Name.Equals(selectedModuleNeedingImportModule, StringComparison.OrdinalIgnoreCase) ? true : false; })); @@ -658,7 +658,7 @@ Function PSGetSerializedShowCommandInfo returnValue.SelectedModule = moduleToSelect; CommandViewModel commandToSelect = moduleToSelect.Commands.Find( - new Predicate(delegate(CommandViewModel command) + new Predicate((command) => { return command.ModuleName.Equals(parentModuleNeedingImportModule, StringComparison.OrdinalIgnoreCase) && command.Name.Equals(commandNeedingImportModule, StringComparison.OrdinalIgnoreCase) ? true : false; @@ -876,11 +876,8 @@ Function PSGetSerializedShowCommandInfo { window.Dispatcher.Invoke( new SendOrPostCallback( - delegate(object ignored) - { - window.Activate(); - }), - string.Empty); + (_) => window.Activate()), + string.Empty); } /// @@ -896,7 +893,7 @@ Function PSGetSerializedShowCommandInfo [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Called using reflection")] private void ShowAllModulesWindow(PSCmdlet cmdlet, Dictionary importedModules, IEnumerable commands, bool noCommonParameter, double windowWidth, double windowHeight, bool passThrough) { - this.methodThatReturnsDialog = new DispatcherOperationCallback(delegate(object ignored) + this.methodThatReturnsDialog = new DispatcherOperationCallback((object ignored) => { ShowAllModulesWindow allModulesWindow = new ShowAllModulesWindow(); this.allModulesViewModel = new AllModulesViewModel(importedModules, commands, noCommonParameter); @@ -939,7 +936,7 @@ Function PSGetSerializedShowCommandInfo this.hostWindow.Dispatcher.Invoke( new SendOrPostCallback( - delegate(object ignored) + (_) => { Window childWindow = (Window)this.methodThatReturnsDialog.Invoke(null); childWindow.Owner = this.hostWindow; @@ -967,7 +964,7 @@ Function PSGetSerializedShowCommandInfo [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Called using reflection")] private void ShowCommandWindow(PSCmdlet cmdlet, object commandViewModelObj, double windowWidth, double windowHeight, bool passThrough) { - this.methodThatReturnsDialog = new DispatcherOperationCallback(delegate(object ignored) + this.methodThatReturnsDialog = new DispatcherOperationCallback((object ignored) => { this.commandViewModel = (CommandViewModel)commandViewModelObj; ShowCommandWindow showCommandWindow = new ShowCommandWindow(); @@ -1034,7 +1031,7 @@ Function PSGetSerializedShowCommandInfo { this.window.Dispatcher.Invoke( new SendOrPostCallback( - delegate(object ignored) + (_) => { string message = ShowCommandHelper.GetImportModuleFailedMessage( this.commandNeedingImportModule,