Refactor delegate types to lambda expressions (#11690)

This commit is contained in:
xtqqczze
2020-01-30 14:50:14 -08:00
committed by GitHub
parent 8ad4997f3c
commit 9a7ee0545a
4 changed files with 27 additions and 30 deletions
@@ -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);
}
@@ -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;
@@ -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
{
@@ -645,7 +645,7 @@ Function PSGetSerializedShowCommandInfo
}
ModuleViewModel moduleToSelect = returnValue.Modules.Find(
new Predicate<ModuleViewModel>(delegate(ModuleViewModel module)
new Predicate<ModuleViewModel>((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<CommandViewModel>(delegate(CommandViewModel command)
new Predicate<CommandViewModel>((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);
}
/// <summary>
@@ -896,7 +893,7 @@ Function PSGetSerializedShowCommandInfo
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Called using reflection")]
private void ShowAllModulesWindow(PSCmdlet cmdlet, Dictionary<string, ShowCommandModuleInfo> importedModules, IEnumerable<ShowCommandCommandInfo> 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,