From 759c4abde811aff1490dec92e438d61e341c3181 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 10 Mar 2019 06:53:31 +0500 Subject: [PATCH] Use `Type.EmptyTypes` and `Array.Empty()` to replace our custom code of the same functionality (#9042) --- .../GetCounterCommand.cs | 2 +- .../ImportCounterCommand.cs | 4 +-- .../commands/management/CombinePathCommand.cs | 2 +- .../management/ControlPanelItemCommand.cs | 2 +- .../commands/management/Eventlog.cs | 2 +- .../management/MovePropertyCommand.cs | 4 +-- .../commands/management/Navigation.cs | 20 +++++------ .../management/PropertyCommandBase.cs | 3 +- .../management/RemovePropertyCommand.cs | 5 +-- .../management/UseTransactionCommand.cs | 2 +- .../management/WriteContentCommandBase.cs | 2 +- .../commands/utility/AddType.cs | 4 +-- .../common/GetFormatDataCommand.cs | 2 +- .../commands/utility/GetAliasCommand.cs | 4 +-- .../utility/ImplicitRemotingCommands.cs | 4 +-- .../commands/utility/InvokeCommandCmdlet.cs | 3 +- .../commands/utility/TimeExpressionCommand.cs | 2 +- .../commands/utility/Update-Data.cs | 4 +-- .../commands/utility/Var.cs | 8 ++--- .../commands/utility/WebCmdlet/JsonObject.cs | 2 +- .../commands/utility/new-object.cs | 2 +- .../commands/utility/neweventcommand.cs | 2 +- .../utility/trace/TraceExpressionCommand.cs | 2 +- .../utility/trace/TraceListenerCommandBase.cs | 2 +- .../Eventing/Reader/EventLogRecord.cs | 2 +- .../Eventing/Reader/NativeWrapper.cs | 20 +++++------ .../security/AclCommands.cs | 4 +-- .../DscSupport/CimDSCParser.cs | 2 +- .../FormatAndOutput/common/BaseCommand.cs | 2 +- .../common/Utilities/MshObjectUtil.cs | 2 +- .../common/Utilities/Mshexpression.cs | 2 +- .../cimSupport/cmdletization/EnumWriter.cs | 2 +- ...lets-over-objects.xmlSerializer.autogen.cs | 2 +- ...lets-over-objects.xmlSerializer.autogen.cs | 2 +- .../engine/Attributes.cs | 6 ++-- .../engine/COM/ComUtil.cs | 2 +- .../engine/CmdletParameterBinderController.cs | 2 +- .../engine/ComInterop/ComEventSink.cs | 10 +++--- .../engine/ComInterop/ComObject.cs | 4 +-- .../engine/ComInterop/ComRuntimeHelpers.cs | 2 +- .../engine/ComInterop/IDispatchComObject.cs | 2 +- .../engine/ComInterop/IDispatchMetaObject.cs | 4 +-- .../CommandCompletion/CommandCompletion.cs | 2 +- .../engine/CommandDiscovery.cs | 2 +- .../engine/CommandPathSearch.cs | 4 +-- .../engine/CompiledCommandParameter.cs | 12 +++---- .../engine/CoreAdapter.cs | 2 +- .../ExperimentalFeature.cs | 2 +- .../engine/GetCommandCommand.cs | 16 ++++----- .../engine/InitialSessionState.cs | 2 +- .../engine/InternalCommands.cs | 10 +++--- .../engine/InvocationInfo.cs | 4 +-- .../engine/LanguagePrimitives.cs | 8 ++--- .../engine/Modules/ImportModuleCommand.cs | 8 ++--- .../engine/Modules/ModuleCmdletBase.cs | 4 +-- .../engine/Modules/ModuleIntrinsics.cs | 4 +-- .../engine/Modules/ModuleUtils.cs | 4 +-- .../engine/Modules/NewModuleCommand.cs | 4 +-- .../engine/Modules/RemoteDiscoveryHelper.cs | 10 +++--- .../engine/Modules/RemoveModuleCommand.cs | 4 +-- .../engine/MshCommandRuntime.cs | 2 +- .../engine/MshMemberInfo.cs | 2 +- .../engine/MshObjectTypeDescriptor.cs | 2 +- .../engine/TypeTable.cs | 2 +- .../engine/Utils.cs | 13 +------ .../engine/debugger/Breakpoint.cs | 2 +- .../engine/hostifaces/History.cs | 4 +-- .../engine/interpreter/InstructionList.cs | 2 +- .../engine/interpreter/LightCompiler.cs | 2 +- .../engine/interpreter/Utilities.cs | 2 +- .../engine/lang/parserutils.cs | 2 +- .../engine/parser/Compiler.cs | 12 +++---- .../engine/parser/PSType.cs | 8 ++--- .../engine/parser/Parser.cs | 4 +-- .../engine/parser/TypeInferenceVisitor.cs | 6 ++-- .../engine/parser/TypeResolver.cs | 2 +- .../engine/parser/ast.cs | 8 ++--- .../engine/regex.cs | 2 +- .../engine/remoting/client/JobManager.cs | 2 +- .../remoting/commands/CustomShellCommands.cs | 34 +++++++++---------- .../commands/NewPSSessionConfigurationFile.cs | 24 ++++++------- .../remoting/commands/PSRemotingCmdlet.cs | 2 +- .../WireDataFormat/RemoteSessionCapability.cs | 2 +- .../engine/remoting/fanin/WSManNativeAPI.cs | 2 +- .../remoting/server/ServerMethodExecutor.cs | 4 +-- .../engine/runtime/Binding/Binders.cs | 12 +++---- .../engine/runtime/CompiledScriptBlock.cs | 6 ++-- .../engine/runtime/Operations/ClassOps.cs | 2 +- .../engine/runtime/ScriptBlockToPowerShell.cs | 2 +- .../help/HelpInfo.cs | 2 +- .../namespaces/RegistryProvider.cs | 4 +-- .../utils/CommandDiscoveryExceptions.cs | 2 +- .../utils/ExtensionMethods.cs | 5 --- .../utils/ParameterBinderExceptions.cs | 4 +-- .../utils/StructuredTraceSource.cs | 2 +- 95 files changed, 219 insertions(+), 232 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs index 0310271a0..feedc344b 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs @@ -171,7 +171,7 @@ namespace Microsoft.PowerShell.Commands set { _computerName = value; } } - private string[] _computerName = new string[0]; + private string[] _computerName = Array.Empty(); private ResourceManager _resourceMgr = null; diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs index eceba8c13..0b34e76d0 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs @@ -82,7 +82,7 @@ namespace Microsoft.PowerShell.Commands set { _listSet = value; } } - private string[] _listSet = new string[0]; + private string[] _listSet = Array.Empty(); // // StartTime parameter @@ -138,7 +138,7 @@ namespace Microsoft.PowerShell.Commands set { _counter = value; } } - private string[] _counter = new string[0]; + private string[] _counter = Array.Empty(); // // Summary switch diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs index 706d92402..e304d4866 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs @@ -41,7 +41,7 @@ namespace Microsoft.PowerShell.Commands [AllowNull] [AllowEmptyString] [AllowEmptyCollection] - public string[] AdditionalChildPath { get; set; } = Utils.EmptyArray(); + public string[] AdditionalChildPath { get; set; } = Array.Empty(); /// /// Determines if the path should be resolved after being joined. diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs index b6178fcde..ce4a44937 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs @@ -268,7 +268,7 @@ $result using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) { ps.AddScript(TestHeadlessServerScript); - Collection psObjectCollection = ps.Invoke(new object[0]); + Collection psObjectCollection = ps.Invoke(Array.Empty()); Dbg.Assert(psObjectCollection != null && psObjectCollection.Count == 1, "invoke should never return null, there should be only one return item"); if (LanguagePrimitives.IsTrue(PSObject.Base(psObjectCollection[0]))) { diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Eventlog.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Eventlog.cs index 63a65fd2f..b0366872c 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Eventlog.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Eventlog.cs @@ -52,7 +52,7 @@ namespace Microsoft.PowerShell.Commands [ValidateNotNullOrEmpty()] [Alias("Cn")] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public string[] ComputerName { get; set; } = new string[0]; + public string[] ComputerName { get; set; } = Array.Empty(); /// /// Read only this number of entries. diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/MovePropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/MovePropertyCommand.cs index 208c04964..5ee9faf2b 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/MovePropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/MovePropertyCommand.cs @@ -58,7 +58,7 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = Utils.EmptyArray(); + value = Array.Empty(); } _property = value; @@ -111,7 +111,7 @@ namespace Microsoft.PowerShell.Commands /// /// The property to be created. /// - private string[] _property = new string[0]; + private string[] _property = Array.Empty(); #endregion parameter data diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index 0258181ec..4a25b95e9 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -188,7 +188,7 @@ namespace Microsoft.PowerShell.Commands { get; set; - } = new string[0]; + } = Array.Empty(); /// /// Gets or sets the exclude property. @@ -202,7 +202,7 @@ namespace Microsoft.PowerShell.Commands { get; set; - } = new string[0]; + } = Array.Empty(); /// /// Gets or sets the force property. @@ -351,7 +351,7 @@ namespace Microsoft.PowerShell.Commands public string[] PSProvider { get => _provider; - set => _provider = value ?? Utils.EmptyArray(); + set => _provider = value ?? Array.Empty(); } /// @@ -401,7 +401,7 @@ namespace Microsoft.PowerShell.Commands /// /// The name of the provider from which to return the current location. /// - private string[] _provider = new string[0]; + private string[] _provider = Array.Empty(); #endregion Location parameter set data @@ -1522,7 +1522,7 @@ namespace Microsoft.PowerShell.Commands public string[] PSProvider { get => _provider; - set => _provider = value ?? Utils.EmptyArray(); + set => _provider = value ?? Array.Empty(); } /// @@ -1563,7 +1563,7 @@ namespace Microsoft.PowerShell.Commands /// /// The name of the provider(s) for which to remove all drives. /// - private string[] _provider = new string[0]; + private string[] _provider = Array.Empty(); #endregion Command data @@ -1717,7 +1717,7 @@ namespace Microsoft.PowerShell.Commands public string[] PSProvider { get => _provider; - set => _provider = value ?? Utils.EmptyArray(); + set => _provider = value ?? Array.Empty(); } #endregion Command parameters @@ -1732,7 +1732,7 @@ namespace Microsoft.PowerShell.Commands /// /// The provider ID for the drives you want to see. /// - private string[] _provider = new string[0]; + private string[] _provider = Array.Empty(); #endregion Command data @@ -4137,7 +4137,7 @@ namespace Microsoft.PowerShell.Commands public string[] PSProvider { get => _provider; - set => _provider = value ?? Utils.EmptyArray(); + set => _provider = value ?? Array.Empty(); } #endregion Command parameters @@ -4146,7 +4146,7 @@ namespace Microsoft.PowerShell.Commands /// /// The string ID of the provider to remove. /// - private string[] _provider = new string[0]; + private string[] _provider = Array.Empty(); #endregion Command data diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/PropertyCommandBase.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/PropertyCommandBase.cs index 94ad7e68a..ff06d1065 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/PropertyCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/PropertyCommandBase.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Management.Automation; using Dbg = System.Management.Automation; @@ -70,7 +71,7 @@ namespace Microsoft.PowerShell.Commands /// /// The path to the item. /// - internal string[] paths = new string[0]; + internal string[] paths = Array.Empty(); #endregion parameter data } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs index d24185c1c..93e1ee0d3 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Management.Automation; using Dbg = System.Management.Automation; @@ -62,7 +63,7 @@ namespace Microsoft.PowerShell.Commands { get { return _property; } - set { _property = value ?? Utils.EmptyArray(); } + set { _property = value ?? Array.Empty(); } } /// @@ -120,7 +121,7 @@ namespace Microsoft.PowerShell.Commands /// /// The property to be created. /// - private string[] _property = new string[0]; + private string[] _property = Array.Empty(); #endregion parameter data diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/UseTransactionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/UseTransactionCommand.cs index 11b38fa73..a65924fb6 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/UseTransactionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/UseTransactionCommand.cs @@ -43,7 +43,7 @@ namespace Microsoft.PowerShell.Commands { try { - var emptyArray = Utils.EmptyArray(); + var emptyArray = Array.Empty(); _transactedScript.InvokeUsingCmdlet( contextCmdlet: this, useLocalScope: false, diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/WriteContentCommandBase.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/WriteContentCommandBase.cs index 17e003675..12148c9ff 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/WriteContentCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/WriteContentCommandBase.cs @@ -98,7 +98,7 @@ namespace Microsoft.PowerShell.Commands if (_content == null) { - _content = new object[0]; + _content = Array.Empty(); } if (_pipingPaths) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index e62dc6744..f733fa51e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -135,7 +135,7 @@ namespace Microsoft.PowerShell.Commands [ValidateNotNull()] [Alias("Using")] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public string[] UsingNamespace { get; set; } = Utils.EmptyArray(); + public string[] UsingNamespace { get; set; } = Array.Empty(); /// /// The path to the source code or DLL to load. @@ -310,7 +310,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] referencedAssemblies = Utils.EmptyArray(); + private string[] referencedAssemblies = Array.Empty(); /// /// The path to the output assembly. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs index 0931cf88f..b2da6495f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs @@ -42,7 +42,7 @@ namespace Microsoft.PowerShell.Commands if (_typename == null) { - _filter = Utils.EmptyArray(); + _filter = Array.Empty(); } else { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs index 3979832a1..5ad08b5ee 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs @@ -41,10 +41,10 @@ namespace Microsoft.PowerShell.Commands { get { return _excludes; } - set { _excludes = value ?? new string[0]; } + set { _excludes = value ?? Array.Empty(); } } - private string[] _excludes = new string[0]; + private string[] _excludes = Array.Empty(); /// /// The scope parameter for the command determines diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index 3bb1e70ef..6d67ac61a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -440,7 +440,7 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = new string[0]; + value = Array.Empty(); } _PSSnapins = value; @@ -449,7 +449,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _PSSnapins = new string[0]; + private string[] _PSSnapins = Array.Empty(); internal bool IsModuleSpecified = false; /// /// Gets or sets the FullyQualifiedModule parameter to the cmdlet. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/InvokeCommandCmdlet.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/InvokeCommandCmdlet.cs index f9f444053..df80155c4 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/InvokeCommandCmdlet.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/InvokeCommandCmdlet.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Management.Automation; using System.Management.Automation.Internal; @@ -42,7 +43,7 @@ namespace Microsoft.PowerShell.Commands myScriptBlock.LanguageMode = PSLanguageMode.ConstrainedLanguage; } - var emptyArray = Utils.EmptyArray(); + var emptyArray = Array.Empty(); myScriptBlock.InvokeUsingCmdlet( contextCmdlet: this, useLocalScope: false, diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs index 0b9ac4f11..c1a8433d0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs @@ -63,7 +63,7 @@ namespace Microsoft.PowerShell.Commands useLocalScope: false, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: InputObject, // $_ - input: new object[0], // $input + input: Array.Empty(), // $input scriptThis: AutomationNull.Value, outputPipe: new Pipe { NullPipe = true }, invocationInfo: null); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-Data.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-Data.cs index 38fece39d..6b2e83e82 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-Data.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-Data.cs @@ -24,14 +24,14 @@ namespace Microsoft.PowerShell.Commands ParameterSetName = FileParameterSet)] [Alias("PSPath", "Path")] [ValidateNotNull] - public string[] AppendPath { set; get; } = Utils.EmptyArray(); + public string[] AppendPath { set; get; } = Array.Empty(); /// /// Files to prepend to the existing set. /// [Parameter(ParameterSetName = FileParameterSet)] [ValidateNotNull] - public string[] PrependPath { set; get; } = Utils.EmptyArray(); + public string[] PrependPath { set; get; } = Array.Empty(); private static void ReportWrongExtension(string file, string errorId, PSCmdlet cmdlet) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs index 5d62d3463..08dd6c311 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs @@ -42,14 +42,14 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = new string[0]; + value = Array.Empty(); } _include = value; } } - private string[] _include = new string[0]; + private string[] _include = Array.Empty(); /// /// The Exclude parameter for all the variable commands. @@ -65,14 +65,14 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = new string[0]; + value = Array.Empty(); } _exclude = value; } } - private string[] _exclude = new string[0]; + private string[] _exclude = Array.Empty(); #region helpers diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs index 5a3552f53..4ac980430 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs @@ -775,7 +775,7 @@ namespace Microsoft.PowerShell.Commands object value; try { - value = getMethod.Invoke(o, new object[0]); + value = getMethod.Invoke(o, Array.Empty()); } catch (Exception) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs index a8cee4d5d..8c584cd30 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs @@ -203,7 +203,7 @@ namespace Microsoft.PowerShell.Commands if (ArgumentList == null || ArgumentList.Length == 0) { - ConstructorInfo ci = type.GetConstructor(PSTypeExtensions.EmptyTypes); + ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes); if (ci != null && ci.IsPublic) { _newObject = CallConstructor(type, new ConstructorInfo[] { ci }, new object[] { }); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/neweventcommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/neweventcommand.cs index 6da52f8e8..3b6b0d6f7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/neweventcommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/neweventcommand.cs @@ -76,7 +76,7 @@ namespace Microsoft.PowerShell.Commands } } - private PSObject[] _eventArguments = new PSObject[0]; + private PSObject[] _eventArguments = Array.Empty(); /// /// Data relating to this event. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs index eb3f2fb89..e5dbcac8a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs @@ -262,7 +262,7 @@ namespace Microsoft.PowerShell.Commands dollarUnder: InputObject, input: new object[] { InputObject }, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); } private object StepCommand() diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs index 30d2d1677..89f696f2f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs @@ -25,7 +25,7 @@ namespace Microsoft.PowerShell.Commands /// The TraceSource parameter determines which TraceSource categories the /// operation will take place on. /// - internal string[] NameInternal { get; set; } = new string[0]; + internal string[] NameInternal { get; set; } = Array.Empty(); /// /// The flags to be set on the TraceSource. diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogRecord.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogRecord.cs index f91640d5e..ab0701c9c 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogRecord.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogRecord.cs @@ -311,7 +311,7 @@ namespace System.Diagnostics.Eventing.Reader if (values == null) return this.FormatDescription(); // copy the value IEnumerable to an array. - string[] theValues = new string[0]; + string[] theValues = Array.Empty(); int i = 0; foreach (object o in values) { diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/NativeWrapper.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/NativeWrapper.cs index 7a5ce0c47..e60771aed 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/NativeWrapper.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/NativeWrapper.cs @@ -1227,32 +1227,32 @@ namespace System.Diagnostics.Eventing.Reader else return false; case (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeBinary: case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeByte): - if (val.Reference == IntPtr.Zero) return new byte[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); byte[] arByte = new byte[val.Count]; Marshal.Copy(val.Reference, arByte, 0, (int)val.Count); return arByte; case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt16): - if (val.Reference == IntPtr.Zero) return new Int16[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); Int16[] arInt16 = new Int16[val.Count]; Marshal.Copy(val.Reference, arInt16, 0, (int)val.Count); return arInt16; case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt32): - if (val.Reference == IntPtr.Zero) return new Int32[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); Int32[] arInt32 = new Int32[val.Count]; Marshal.Copy(val.Reference, arInt32, 0, (int)val.Count); return arInt32; case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt64): - if (val.Reference == IntPtr.Zero) return new Int64[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); Int64[] arInt64 = new Int64[val.Count]; Marshal.Copy(val.Reference, arInt64, 0, (int)val.Count); return arInt64; case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeSingle): - if (val.Reference == IntPtr.Zero) return new Single[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); Single[] arSingle = new Single[val.Count]; Marshal.Copy(val.Reference, arSingle, 0, (int)val.Count); return arSingle; case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeDouble): - if (val.Reference == IntPtr.Zero) return new Double[0]; + if (val.Reference == IntPtr.Zero) return Array.Empty(); Double[] arDouble = new Double[val.Count]; Marshal.Copy(val.Reference, arDouble, 0, (int)val.Count); return arDouble; @@ -1351,7 +1351,7 @@ namespace System.Diagnostics.Eventing.Reader IntPtr ptr = val.Reference; if (ptr == IntPtr.Zero) { - return new bool[0]; + return Array.Empty(); } else { @@ -1373,7 +1373,7 @@ namespace System.Diagnostics.Eventing.Reader IntPtr ptr = val.Reference; if (ptr == IntPtr.Zero) { - return new DateTime[0]; + return Array.Empty(); } else { @@ -1394,7 +1394,7 @@ namespace System.Diagnostics.Eventing.Reader IntPtr ptr = val.Reference; if (ptr == IntPtr.Zero) { - return new DateTime[0]; + return Array.Empty(); } else { @@ -1415,7 +1415,7 @@ namespace System.Diagnostics.Eventing.Reader { if (val.Reference == IntPtr.Zero) { - return new string[0]; + return Array.Empty(); } else { diff --git a/src/Microsoft.PowerShell.Security/security/AclCommands.cs b/src/Microsoft.PowerShell.Security/security/AclCommands.cs index bc8e06326..576b0018e 100644 --- a/src/Microsoft.PowerShell.Security/security/AclCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/AclCommands.cs @@ -608,12 +608,12 @@ namespace Microsoft.PowerShell.Commands /// /// The glob string used to determine which items are included. /// - private string[] _include = new string[0]; + private string[] _include = Array.Empty(); /// /// The glob string used to determine which items are excluded. /// - private string[] _exclude = new string[0]; + private string[] _exclude = Array.Empty(); } #if !UNIX diff --git a/src/System.Management.Automation/DscSupport/CimDSCParser.cs b/src/System.Management.Automation/DscSupport/CimDSCParser.cs index 8e0586ab3..8c57b70a3 100644 --- a/src/System.Management.Automation/DscSupport/CimDSCParser.cs +++ b/src/System.Management.Automation/DscSupport/CimDSCParser.cs @@ -2797,7 +2797,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal else if (!type.IsAbstract) { // Must have default constructor, at least 1 public property/field, and no base classes - if (type.GetConstructor(PSTypeExtensions.EmptyTypes) == null) + if (type.GetConstructor(Type.EmptyTypes) == null) { missingDefaultConstructor = true; } diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs index 19be44842..3ec199835 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs @@ -92,7 +92,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { // if Process() never got called, no sub pipeline // ever got created, hence we just return an empty array - return new object[0]; + return Array.Empty(); } PipelineProcessor ppTemp = _pp; diff --git a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshObjectUtil.cs b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshObjectUtil.cs index df222bae9..e201f2479 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshObjectUtil.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshObjectUtil.cs @@ -236,7 +236,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format } else { - MethodInfo toStringMethod = x.GetType().GetMethod("ToString", PSTypeExtensions.EmptyTypes); + MethodInfo toStringMethod = x.GetType().GetMethod("ToString", Type.EmptyTypes); // TODO:CORECLR double check with CORE CLR that x.GetType() == toStringMethod.ReflectedType // Check if the given object "x" implements "toString" method. Do that by comparing "DeclaringType" which 'Gets the class that declares this member' and the object type if (toStringMethod.DeclaringType == x.GetType()) diff --git a/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs b/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs index af0cd249c..286cc9e14 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs @@ -313,7 +313,7 @@ namespace Microsoft.PowerShell.Commands dollarUnder: target, input: AutomationNull.Value, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); } else { diff --git a/src/System.Management.Automation/cimSupport/cmdletization/EnumWriter.cs b/src/System.Management.Automation/cimSupport/cmdletization/EnumWriter.cs index f0a70e5b1..0959f5e39 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/EnumWriter.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/EnumWriter.cs @@ -53,7 +53,7 @@ namespace Microsoft.PowerShell.Cmdletization if (enumMetadata.BitwiseFlagsSpecified && enumMetadata.BitwiseFlags) { - var cab = new CustomAttributeBuilder(typeof(FlagsAttribute).GetConstructor(PSTypeExtensions.EmptyTypes), new object[0]); + var cab = new CustomAttributeBuilder(typeof(FlagsAttribute).GetConstructor(Type.EmptyTypes), Array.Empty()); eb.SetCustomAttribute(cab); } diff --git a/src/System.Management.Automation/cimSupport/cmdletization/xml/CoreCLR/cmdlets-over-objects.xmlSerializer.autogen.cs b/src/System.Management.Automation/cimSupport/cmdletization/xml/CoreCLR/cmdlets-over-objects.xmlSerializer.autogen.cs index ee9c5155b..69fbe8217 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/xml/CoreCLR/cmdlets-over-objects.xmlSerializer.autogen.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/xml/CoreCLR/cmdlets-over-objects.xmlSerializer.autogen.cs @@ -2791,7 +2791,7 @@ namespace Microsoft.PowerShell.Cmdletization.Xml if (isNull) return null; global::System.Object o; o = new global::System.Object(); - bool[] paramsRead = new bool[0]; + bool[] paramsRead = Array.Empty(); while (Reader.MoveToNextAttribute()) { if (!IsXmlnsAttribute(Reader.Name)) diff --git a/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs b/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs index ce8053e7b..3711ad54c 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs @@ -5143,7 +5143,7 @@ namespace Microsoft.PowerShell.Cmdletization.Xml if (isNull) return null; global::System.Object o; o = new global::System.Object(); - bool[] paramsRead = new bool[0]; + bool[] paramsRead = Array.Empty(); while (Reader.MoveToNextAttribute()) { if (!IsXmlnsAttribute(Reader.Name)) diff --git a/src/System.Management.Automation/engine/Attributes.cs b/src/System.Management.Automation/engine/Attributes.cs index 39877844e..f82e37e11 100644 --- a/src/System.Management.Automation/engine/Attributes.cs +++ b/src/System.Management.Automation/engine/Attributes.cs @@ -506,7 +506,7 @@ namespace System.Management.Automation } else { - Type = Utils.EmptyArray(); + Type = Array.Empty(); } } @@ -526,7 +526,7 @@ namespace System.Management.Automation } else { - Type = Utils.EmptyArray(); + Type = Array.Empty(); } } @@ -1427,7 +1427,7 @@ namespace System.Management.Automation dollarUnder: LanguagePrimitives.AsPSObjectOrNull(element), input: AutomationNull.Value, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); if (!LanguagePrimitives.IsTrue(result)) { diff --git a/src/System.Management.Automation/engine/COM/ComUtil.cs b/src/System.Management.Automation/engine/COM/ComUtil.cs index e86c391ba..e23839c6f 100644 --- a/src/System.Management.Automation/engine/COM/ComUtil.cs +++ b/src/System.Management.Automation/engine/COM/ComUtil.cs @@ -423,7 +423,7 @@ namespace System.Management.Automation // The COM object is a collection and also a IDispatch interface, so we try to get a // IEnumVARIANT interface out of it by invoking its '_NewEnum (DispId: -4)' function. var result = ComInvoker.Invoke(target, ComTypeInfo.DISPID_NEWENUM, - args: Utils.EmptyArray(), byRef: null, + args: Array.Empty(), byRef: null, invokeKind: comTypeInfo.NewEnumInvokeKind.Value); enumVariant = result as COM.IEnumVARIANT; if (enumVariant != null) diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs index 38fd3cedd..530e967c7 100644 --- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs +++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs @@ -3792,7 +3792,7 @@ namespace System.Management.Automation { try { - output = script.DoInvoke(inputToOperateOn, inputToOperateOn, Utils.EmptyArray()); + output = script.DoInvoke(inputToOperateOn, inputToOperateOn, Array.Empty()); delayedScriptBlock.Value._evaluatedArgument = output; } catch (RuntimeException runtimeException) diff --git a/src/System.Management.Automation/engine/ComInterop/ComEventSink.cs b/src/System.Management.Automation/engine/ComInterop/ComEventSink.cs index 110180405..9ac480aa6 100644 --- a/src/System.Management.Automation/engine/ComInterop/ComEventSink.cs +++ b/src/System.Management.Automation/engine/ComInterop/ComEventSink.cs @@ -219,17 +219,17 @@ namespace System.Management.Automation.ComInterop public FieldInfo[] GetFields(BindingFlags bindingAttr) { - return Utils.EmptyArray(); + return Array.Empty(); } public MemberInfo[] GetMember(string name, BindingFlags bindingAttr) { - return Utils.EmptyArray(); + return Array.Empty(); } public MemberInfo[] GetMembers(BindingFlags bindingAttr) { - return Utils.EmptyArray(); + return Array.Empty(); } public MethodInfo GetMethod(string name, BindingFlags bindingAttr) @@ -244,7 +244,7 @@ namespace System.Management.Automation.ComInterop public MethodInfo[] GetMethods(BindingFlags bindingAttr) { - return Utils.EmptyArray(); + return Array.Empty(); } public PropertyInfo GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) @@ -259,7 +259,7 @@ namespace System.Management.Automation.ComInterop public PropertyInfo[] GetProperties(BindingFlags bindingAttr) { - return Utils.EmptyArray(); + return Array.Empty(); } #endregion diff --git a/src/System.Management.Automation/engine/ComInterop/ComObject.cs b/src/System.Management.Automation/engine/ComInterop/ComObject.cs index 936dab979..ae8eacd1a 100644 --- a/src/System.Management.Automation/engine/ComInterop/ComObject.cs +++ b/src/System.Management.Automation/engine/ComInterop/ComObject.cs @@ -104,12 +104,12 @@ namespace System.Management.Automation.ComInterop internal virtual IList GetMemberNames(bool dataOnly) { - return Utils.EmptyArray(); + return Array.Empty(); } internal virtual IList> GetMembers(IEnumerable names) { - return Utils.EmptyArray>(); + return Array.Empty>(); } DynamicMetaObject IDynamicMetaObjectProvider.GetMetaObject(Expression parameter) diff --git a/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs b/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs index 276f0e340..eeb87a0d8 100644 --- a/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs +++ b/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs @@ -641,7 +641,7 @@ namespace System.Management.Automation.ComInterop if (s_dynamicModule == null) { var attributes = new[] { - new CustomAttributeBuilder(typeof(UnverifiableCodeAttribute).GetConstructor(Type.EmptyTypes), Utils.EmptyArray()), + new CustomAttributeBuilder(typeof(UnverifiableCodeAttribute).GetConstructor(Type.EmptyTypes), Array.Empty()), // PermissionSet(SecurityAction.Demand, Unrestricted = true) new CustomAttributeBuilder(typeof(PermissionSetAttribute).GetConstructor(new Type[] { typeof(SecurityAction) }), new object[] { SecurityAction.Demand }, diff --git a/src/System.Management.Automation/engine/ComInterop/IDispatchComObject.cs b/src/System.Management.Automation/engine/ComInterop/IDispatchComObject.cs index e739cad34..f2ee58208 100644 --- a/src/System.Management.Automation/engine/ComInterop/IDispatchComObject.cs +++ b/src/System.Management.Automation/engine/ComInterop/IDispatchComObject.cs @@ -333,7 +333,7 @@ namespace System.Management.Automation.ComInterop BindingFlags.GetProperty, null, RuntimeCallableWrapper, - Utils.EmptyArray(), + Array.Empty(), CultureInfo.InvariantCulture ); members.Add(new KeyValuePair(method.Name, value)); diff --git a/src/System.Management.Automation/engine/ComInterop/IDispatchMetaObject.cs b/src/System.Management.Automation/engine/ComInterop/IDispatchMetaObject.cs index 1069fccb6..2f7859a06 100644 --- a/src/System.Management.Automation/engine/ComInterop/IDispatchMetaObject.cs +++ b/src/System.Management.Automation/engine/ComInterop/IDispatchMetaObject.cs @@ -150,14 +150,14 @@ namespace System.Management.Automation.ComInterop { if (method.ParamCount == 0) { - return BindComInvoke(DynamicMetaObject.EmptyMetaObjects, method, new CallInfo(0), Utils.EmptyArray(), null, null); + return BindComInvoke(DynamicMetaObject.EmptyMetaObjects, method, new CallInfo(0), Array.Empty(), null, null); } } // ComGetMemberBinder does not expect callables. Try to call always. if (!canReturnCallables) { - return BindComInvoke(DynamicMetaObject.EmptyMetaObjects, method, new CallInfo(0), Utils.EmptyArray(), null, null); + return BindComInvoke(DynamicMetaObject.EmptyMetaObjects, method, new CallInfo(0), Array.Empty(), null, null); } return new DynamicMetaObject( diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index b0defa1db..05bbdfcd4 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -55,7 +55,7 @@ namespace System.Management.Automation [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public Collection CompletionMatches { get; set; } - internal static readonly IList EmptyCompletionResult = Utils.EmptyArray(); + internal static readonly IList EmptyCompletionResult = Array.Empty(); private static readonly CommandCompletion s_emptyCommandCompletion = new CommandCompletion( new Collection(EmptyCompletionResult), -1, -1, -1); diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 239356f3d..5ad7717f0 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -1420,7 +1420,7 @@ namespace System.Management.Automation { s_cachedPathExtCollection = pathExt != null ? pathExt.Split(Utils.Separators.PathSeparator, StringSplitOptions.RemoveEmptyEntries) - : Utils.EmptyArray(); + : Array.Empty(); s_cachedPathExtCollectionWithPs1 = new string[s_cachedPathExtCollection.Length + 1]; s_cachedPathExtCollectionWithPs1[0] = StringLiterals.PowerShellScriptFileExtension; Array.Copy(s_cachedPathExtCollection, 0, s_cachedPathExtCollectionWithPs1, 1, s_cachedPathExtCollection.Length); diff --git a/src/System.Management.Automation/engine/CommandPathSearch.cs b/src/System.Management.Automation/engine/CommandPathSearch.cs index 644b07be2..57b57f676 100644 --- a/src/System.Management.Automation/engine/CommandPathSearch.cs +++ b/src/System.Management.Automation/engine/CommandPathSearch.cs @@ -349,7 +349,7 @@ namespace System.Management.Automation { _lookupPathsEnumerator = _lookupPaths.GetEnumerator(); _patternEnumerator = _patterns.GetEnumerator(); - _currentDirectoryResults = Utils.EmptyArray(); + _currentDirectoryResults = Array.Empty(); _currentDirectoryResultsEnumerator = _currentDirectoryResults.GetEnumerator(); _justReset = true; } @@ -468,7 +468,7 @@ namespace System.Management.Automation // accessible } - _currentDirectoryResults = result ?? Utils.EmptyArray(); + _currentDirectoryResults = result ?? Array.Empty(); _currentDirectoryResultsEnumerator = _currentDirectoryResults.GetEnumerator(); } diff --git a/src/System.Management.Automation/engine/CompiledCommandParameter.cs b/src/System.Management.Automation/engine/CompiledCommandParameter.cs index 75f8f6db4..a507fef10 100644 --- a/src/System.Management.Automation/engine/CompiledCommandParameter.cs +++ b/src/System.Management.Automation/engine/CompiledCommandParameter.cs @@ -89,13 +89,13 @@ namespace System.Management.Automation } this.ValidationAttributes = validationAttributes == null - ? Utils.EmptyArray() + ? Array.Empty() : validationAttributes.ToArray(); this.ArgumentTransformationAttributes = argTransformationAttributes == null - ? Utils.EmptyArray() + ? Array.Empty() : argTransformationAttributes.ToArray(); this.Aliases = aliases == null - ? Utils.EmptyArray() + ? Array.Empty() : aliases.ToArray(); } @@ -180,12 +180,12 @@ namespace System.Management.Automation } this.ValidationAttributes = validationAttributes == null - ? Utils.EmptyArray() + ? Array.Empty() : validationAttributes.ToArray(); this.ArgumentTransformationAttributes = argTransformationAttributes == null - ? Utils.EmptyArray() + ? Array.Empty() : argTransformationAttributes.ToArray(); - this.Aliases = aliases ?? Utils.EmptyArray(); + this.Aliases = aliases ?? Array.Empty(); } #endregion ctor diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index 1699a2374..f2e745e4b 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -1624,7 +1624,7 @@ namespace System.Management.Automation int parametersLength = parameters.Length; if (parametersLength == 0) { - return Utils.EmptyArray(); + return Array.Empty(); } object[] retValue = new object[parametersLength]; diff --git a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs index 9fe90d336..443720eb4 100644 --- a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs +++ b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs @@ -128,7 +128,7 @@ namespace System.Management.Automation // 3. We don't need to decide where/when to read the config file for the enabled experimental features, // instead, it will be done when the type is used for the first time, which is always earlier than // any experimental features take effect. - string[] enabledFeatures = Utils.EmptyArray(); + string[] enabledFeatures = Array.Empty(); try { enabledFeatures = PowerShellConfig.Instance.GetExperimentalFeatures(); diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index 026bdcd12..832134039 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -84,7 +84,7 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = Utils.EmptyArray(); + value = Array.Empty(); } _verbs = value; @@ -92,7 +92,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _verbs = Utils.EmptyArray(); + private string[] _verbs = Array.Empty(); /// /// Gets or sets the noun parameter to the cmdlet. @@ -110,7 +110,7 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = Utils.EmptyArray(); + value = Array.Empty(); } _nouns = value; @@ -118,7 +118,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _nouns = Utils.EmptyArray(); + private string[] _nouns = Array.Empty(); /// /// Gets or sets the PSSnapin/Module parameter to the cmdlet. @@ -137,7 +137,7 @@ namespace Microsoft.PowerShell.Commands { if (value == null) { - value = Utils.EmptyArray(); + value = Array.Empty(); } _modules = value; @@ -147,7 +147,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _modules = Utils.EmptyArray(); + private string[] _modules = Array.Empty(); private bool _isModuleSpecified = false; /// @@ -173,7 +173,7 @@ namespace Microsoft.PowerShell.Commands } } - private ModuleSpecification[] _moduleSpecifications = Utils.EmptyArray(); + private ModuleSpecification[] _moduleSpecifications = Array.Empty(); private bool _isFullyQualifiedModuleSpecified = false; /// @@ -1496,7 +1496,7 @@ namespace Microsoft.PowerShell.Commands if (parameterSets == null) { - return Utils.EmptyArray(); + return Array.Empty(); } List returnParameterSets = new List(cmdInfo.ParameterSets.Count); diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 852c7e881..68860b90e 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5342,7 +5342,7 @@ end { [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool HasDefaultConstructor(Type type) { - return !(type.GetConstructor(PSTypeExtensions.EmptyTypes) == null); + return !(type.GetConstructor(Type.EmptyTypes) == null); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index bbad7df9a..1492fe960 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -269,7 +269,7 @@ namespace Microsoft.PowerShell.Commands if (_scripts[0] == null) return; - var emptyArray = Utils.EmptyArray(); + var emptyArray = Array.Empty(); _scripts[0].InvokeUsingCmdlet( contextCmdlet: this, useLocalScope: false, @@ -309,7 +309,7 @@ namespace Microsoft.PowerShell.Commands dollarUnder: InputObject, input: new object[] { InputObject }, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); } } @@ -434,7 +434,7 @@ namespace Microsoft.PowerShell.Commands { if (!BlockMethodInLanguageMode(InputObject)) { - object result = targetMethod.Invoke(Utils.EmptyArray()); + object result = targetMethod.Invoke(Array.Empty()); WriteToPipelineWithUnrolling(result); } } @@ -849,7 +849,7 @@ namespace Microsoft.PowerShell.Commands if (_endScript == null) return; - var emptyArray = Utils.EmptyArray(); + var emptyArray = Array.Empty(); _endScript.InvokeUsingCmdlet( contextCmdlet: this, useLocalScope: false, @@ -1634,7 +1634,7 @@ namespace Microsoft.PowerShell.Commands dollarUnder: InputObject, input: new object[] { _inputObject }, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); if (_toBoolSite.Target.Invoke(_toBoolSite, result)) { diff --git a/src/System.Management.Automation/engine/InvocationInfo.cs b/src/System.Management.Automation/engine/InvocationInfo.cs index af02544f2..45fcc921a 100644 --- a/src/System.Management.Automation/engine/InvocationInfo.cs +++ b/src/System.Management.Automation/engine/InvocationInfo.cs @@ -128,7 +128,7 @@ namespace System.Management.Automation } else { - PipelineIterationInfo = Utils.EmptyArray(); + PipelineIterationInfo = Array.Empty(); } // @@ -399,7 +399,7 @@ namespace System.Management.Automation /// /// All the commands in a given pipeline share the same PipelinePositionInfo. /// - internal int[] PipelineIterationInfo { get; set; } = Utils.EmptyArray(); + internal int[] PipelineIterationInfo { get; set; } = Array.Empty(); /// /// Adds the information about this informational record to a PSObject as note properties. diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 93ecdbeff..9a732bcca 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -1757,7 +1757,7 @@ namespace System.Management.Automation { if (valueToConvert != null) { - ConstructorInfo toConstructor = resultType.GetConstructor(PSTypeExtensions.EmptyTypes); + ConstructorInfo toConstructor = resultType.GetConstructor(Type.EmptyTypes); ConvertViaNoArgumentConstructor noArgumentConstructorConverter = new ConvertViaNoArgumentConstructor(toConstructor, resultType); return noArgumentConstructorConverter.Convert(PSObject.Base(valueToConvert), resultType, recursion, (PSObject)valueToConvert, formatProvider, null, ignoreUnknownMembers); } @@ -5005,7 +5005,7 @@ namespace System.Management.Automation { Type actualResultType = typeof(PSObject); - ConstructorInfo resultConstructor = actualResultType.GetConstructor(PSTypeExtensions.EmptyTypes); + ConstructorInfo resultConstructor = actualResultType.GetConstructor(Type.EmptyTypes); var converterObj = new ConvertViaNoArgumentConstructor(resultConstructor, actualResultType); return CacheConversion(fromType, toType, converterObj.Convert, ConversionRank.Language); @@ -5441,7 +5441,7 @@ namespace System.Management.Automation ConstructorInfo toConstructor = null; try { - toConstructor = toType.GetConstructor(PSTypeExtensions.EmptyTypes); + toConstructor = toType.GetConstructor(Type.EmptyTypes); } catch (AmbiguousMatchException e) { @@ -5663,7 +5663,7 @@ namespace System.Management.Automation // If the ToType has a constructor that takes a hashtable or OrderedDictionary, // then it would have been returned as the constructor during FigureConstructorConversion // So, we need to check only for the first condition - ConstructorInfo resultConstructor = toType.GetConstructor(PSTypeExtensions.EmptyTypes); + ConstructorInfo resultConstructor = toType.GetConstructor(Type.EmptyTypes); if (resultConstructor != null || (toType.IsValueType && !toType.IsPrimitive)) { diff --git a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs index c1f5547df..fb272cdc4 100644 --- a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs @@ -81,7 +81,7 @@ namespace Microsoft.PowerShell.Commands [Parameter(ParameterSetName = ParameterSet_ViaCimSession, Mandatory = true, ValueFromPipeline = true, Position = 0)] [ValidateTrustedData] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Cmdlets use arrays for parameters.")] - public string[] Name { set; get; } = Utils.EmptyArray(); + public string[] Name { set; get; } = Array.Empty(); /// /// This parameter specifies the current pipeline object. @@ -125,7 +125,7 @@ namespace Microsoft.PowerShell.Commands get { return _functionImportList; } } - private string[] _functionImportList = Utils.EmptyArray(); + private string[] _functionImportList = Array.Empty(); /// /// This patterns matching the names of cmdlets to import from the module... @@ -153,7 +153,7 @@ namespace Microsoft.PowerShell.Commands get { return _cmdletImportList; } } - private string[] _cmdletImportList = Utils.EmptyArray(); + private string[] _cmdletImportList = Array.Empty(); /// /// This parameter specifies the variables to import from the module... @@ -316,7 +316,7 @@ namespace Microsoft.PowerShell.Commands [Parameter(ParameterSetName = ParameterSet_ModuleInfo, Mandatory = true, ValueFromPipeline = true, Position = 0)] [ValidateTrustedData] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Cmdlets use arrays for parameters.")] - public PSModuleInfo[] ModuleInfo { set; get; } = Utils.EmptyArray(); + public PSModuleInfo[] ModuleInfo { set; get; } = Array.Empty(); /// /// The arguments to pass to the module script. diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index a6b09a399..ac7da934a 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -1065,7 +1065,7 @@ namespace Microsoft.PowerShell.Commands } // Make sure we always return a non-null collection. - return allModules ?? Utils.EmptyArray(); + return allModules ?? Array.Empty(); } /// @@ -5732,7 +5732,7 @@ namespace Microsoft.PowerShell.Commands scriptThis: AutomationNull.Value, outputPipe: ((MshCommandRuntime)this.CommandRuntime).OutputPipe, invocationInfo: invocationInfo, - args: this.BaseArgumentList ?? Utils.EmptyArray()); + args: this.BaseArgumentList ?? Array.Empty()); } finally { diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index c492deb01..a36b69053 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -228,7 +228,7 @@ namespace System.Management.Automation scriptThis: AutomationNull.Value, outputPipe: outputPipe, invocationInfo: invocationInfo, - args: arguments ?? Utils.EmptyArray()); + args: arguments ?? Array.Empty()); } catch (ExitException ee) { @@ -879,7 +879,7 @@ namespace System.Management.Automation } catch (PSInvalidOperationException) { } - return Utils.EmptyArray(); + return Array.Empty(); } // The extensions of all of the files that can be processed with Import-Module, put the ni.dll in front of .dll to have higher priority to be loaded. diff --git a/src/System.Management.Automation/engine/Modules/ModuleUtils.cs b/src/System.Management.Automation/engine/Modules/ModuleUtils.cs index 0c24fa002..004bfc81b 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleUtils.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleUtils.cs @@ -266,8 +266,8 @@ namespace System.Management.Automation.Internal subdirectories = Directory.GetDirectories(directoryToCheck, "*", options); ProcessPossibleVersionSubdirectories(subdirectories, versionDirectories); } - catch (IOException) { subdirectories = Utils.EmptyArray(); } - catch (UnauthorizedAccessException) { subdirectories = Utils.EmptyArray(); } + catch (IOException) { subdirectories = Array.Empty(); } + catch (UnauthorizedAccessException) { subdirectories = Array.Empty(); } bool isModuleDirectory = false; string proposedModuleName = Path.GetFileName(directoryToCheck); diff --git a/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs index 5e3b13379..eb4dec68f 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs @@ -78,7 +78,7 @@ namespace Microsoft.PowerShell.Commands get { return _functionImportList; } } - private string[] _functionImportList = Utils.EmptyArray(); + private string[] _functionImportList = Array.Empty(); /// /// This parameter specifies the patterns matching the cmdlets to import from the module... @@ -106,7 +106,7 @@ namespace Microsoft.PowerShell.Commands get { return _cmdletImportList; } } - private string[] _cmdletImportList = Utils.EmptyArray(); + private string[] _cmdletImportList = Array.Empty(); /// /// This parameter causes the session state instance to be written... diff --git a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs index 99f665fdf..126527db1 100644 --- a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs +++ b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs @@ -660,7 +660,7 @@ namespace System.Management.Automation { get { - byte[] rawFileData = GetPropertyValue(_baseObject, "moduleManifestFileData", Utils.EmptyArray()); + byte[] rawFileData = GetPropertyValue(_baseObject, "moduleManifestFileData", Array.Empty()); return new CimModuleManifestFile(this.ModuleName + ".psd1", rawFileData); } } @@ -728,7 +728,7 @@ namespace System.Management.Automation internal override byte[] RawFileDataCore { - get { return GetPropertyValue(_baseObject, "FileData", Utils.EmptyArray()); } + get { return GetPropertyValue(_baseObject, "FileData", Array.Empty()); } } } } @@ -851,9 +851,9 @@ namespace System.Management.Automation IEnumerable typesToProcess, IEnumerable formatsToProcess) { - nestedModules = nestedModules ?? Utils.EmptyArray(); - typesToProcess = typesToProcess ?? Utils.EmptyArray(); - formatsToProcess = formatsToProcess ?? Utils.EmptyArray(); + nestedModules = nestedModules ?? Array.Empty(); + typesToProcess = typesToProcess ?? Array.Empty(); + formatsToProcess = formatsToProcess ?? Array.Empty(); var newManifest = new Hashtable(StringComparer.OrdinalIgnoreCase); newManifest["NestedModules"] = nestedModules; diff --git a/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs b/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs index 950faa6a6..28596742b 100644 --- a/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs @@ -36,7 +36,7 @@ namespace Microsoft.PowerShell.Commands get { return _name; } } - private string[] _name = Utils.EmptyArray(); + private string[] _name = Array.Empty(); /// /// This parameter specifies the current pipeline object. @@ -57,7 +57,7 @@ namespace Microsoft.PowerShell.Commands get { return _moduleInfo; } } - private PSModuleInfo[] _moduleInfo = Utils.EmptyArray(); + private PSModuleInfo[] _moduleInfo = Array.Empty(); /// /// If provided, this parameter will allow readonly modules to be removed. diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index d56d22686..ef1cd5fba 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -2199,7 +2199,7 @@ namespace System.Management.Automation /// An empty array that is declared statically so we don't keep /// allocating them over and over... /// - internal static object[] StaticEmptyArray = Utils.EmptyArray(); + internal static object[] StaticEmptyArray = Array.Empty(); /// /// Gets or sets the error pipe. diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index bb6229905..aff5e7635 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -1856,7 +1856,7 @@ namespace System.Management.Automation dollarUnder: AutomationNull.Value, input: AutomationNull.Value, scriptThis: scriptThis, - args: Utils.EmptyArray()); + args: Array.Empty()); } catch (RuntimeException e) { diff --git a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs index 687cac7b7..f7e6e50be 100644 --- a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs +++ b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs @@ -95,7 +95,7 @@ namespace System.Management.Automation internal event EventHandler GettingValueException; internal PSObjectPropertyDescriptor(string propertyName, Type propertyType, bool isReadOnly, AttributeCollection propertyAttributes) - : base(propertyName, Utils.EmptyArray()) + : base(propertyName, Array.Empty()) { IsReadOnly = isReadOnly; Attributes = propertyAttributes; diff --git a/src/System.Management.Automation/engine/TypeTable.cs b/src/System.Management.Automation/engine/TypeTable.cs index ca039f862..437cf401e 100644 --- a/src/System.Management.Automation/engine/TypeTable.cs +++ b/src/System.Management.Automation/engine/TypeTable.cs @@ -1488,7 +1488,7 @@ namespace System.Management.Automation.Runspaces UpdateKey(); } - internal static readonly ConsolidatedString Empty = new ConsolidatedString(Utils.EmptyArray()); + internal static readonly ConsolidatedString Empty = new ConsolidatedString(Array.Empty()); internal static IEqualityComparer EqualityComparer = new ConsolidatedStringEqualityComparer(); diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 5ef3339ea..f4520be4b 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1212,26 +1212,15 @@ namespace System.Management.Automation return commandName; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static T[] EmptyArray() - { - return EmptyArrayHolder._instance; - } - internal static ReadOnlyCollection EmptyReadOnlyCollection() { return EmptyReadOnlyCollectionHolder._instance; } - private static class EmptyArrayHolder - { - internal static readonly T[] _instance = new T[0]; - } - private static class EmptyReadOnlyCollectionHolder { internal static readonly ReadOnlyCollection _instance = - new ReadOnlyCollection(EmptyArray()); + new ReadOnlyCollection(Array.Empty()); } internal static class Separators diff --git a/src/System.Management.Automation/engine/debugger/Breakpoint.cs b/src/System.Management.Automation/engine/debugger/Breakpoint.cs index f2339da78..07c0f26ec 100644 --- a/src/System.Management.Automation/engine/debugger/Breakpoint.cs +++ b/src/System.Management.Automation/engine/debugger/Breakpoint.cs @@ -94,7 +94,7 @@ namespace System.Management.Automation // implement a "trigger once" breakpoint that disables itself after first hit. // One could also share an action across many breakpoints - and hence needs // to know something about the breakpoint that is hit, e.g. in a poor mans code coverage tool. - Action.DoInvoke(dollarUnder: this, input: null, args: Utils.EmptyArray()); + Action.DoInvoke(dollarUnder: this, input: null, args: Array.Empty()); } catch (BreakException) { diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index e0001d836..3347f9be1 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -297,7 +297,7 @@ namespace Microsoft.PowerShell.Commands if (count == 0 || _countEntriesInBuffer == 0) { - return Utils.EmptyArray(); + return Array.Empty(); } lock (_syncRoot) @@ -1119,7 +1119,7 @@ namespace Microsoft.PowerShell.Commands try { // Indicate to the system that we are in nested prompt mode, since we are emulating running the command at the prompt. - // This ensures that the command being run as nested runs in the correct language mode, because CreatePipelineProcessor() + // This ensures that the command being run as nested runs in the correct language mode, because CreatePipelineProcessor() // always forces CommandOrigin to Internal for nested running commands, and Command.CreateCommandProcessor() forces Internal // commands to always run in FullLanguage mode unless in a nested prompt. if (localRunspace != null) diff --git a/src/System.Management.Automation/engine/interpreter/InstructionList.cs b/src/System.Management.Automation/engine/interpreter/InstructionList.cs index 88190afd6..9617c7463 100644 --- a/src/System.Management.Automation/engine/interpreter/InstructionList.cs +++ b/src/System.Management.Automation/engine/interpreter/InstructionList.cs @@ -130,7 +130,7 @@ namespace System.Management.Automation.Interpreter int stackDepth = 0; int continuationsDepth = 0; - var cookieEnumerator = (debugCookies ?? Automation.Utils.EmptyArray>()).GetEnumerator(); + var cookieEnumerator = (debugCookies ?? Array.Empty>()).GetEnumerator(); var hasCookie = cookieEnumerator.MoveNext(); for (int i = 0; i < instructions.Count; i++) diff --git a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs index cd2bd6ad1..e05965cb8 100644 --- a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs +++ b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs @@ -288,7 +288,7 @@ namespace System.Management.Automation.Interpreter private readonly LightCompiler _parent; - private static LocalDefinition[] s_emptyLocals = Automation.Utils.EmptyArray(); + private static LocalDefinition[] s_emptyLocals = Array.Empty(); public LightCompiler(int compilationThreshold) { diff --git a/src/System.Management.Automation/engine/interpreter/Utilities.cs b/src/System.Management.Automation/engine/interpreter/Utilities.cs index b1e527102..fd3cbfb88 100644 --- a/src/System.Management.Automation/engine/interpreter/Utilities.cs +++ b/src/System.Management.Automation/engine/interpreter/Utilities.cs @@ -682,7 +682,7 @@ namespace System.Management.Automation.Interpreter internal class ThreadLocal { private StorageInfo[] _stores; // array of storage indexed by managed thread ID - private static readonly StorageInfo[] s_updating = Automation.Utils.EmptyArray(); // a marker used when updating the array + private static readonly StorageInfo[] s_updating = Array.Empty(); // a marker used when updating the array private readonly bool _refCounted; public ThreadLocal() diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index 8ab4229f5..a55561d60 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -990,7 +990,7 @@ namespace System.Management.Automation dollarUnder: match, input: AutomationNull.Value, scriptThis: AutomationNull.Value, - args: Utils.EmptyArray()); + args: Array.Empty()); return PSObject.ToStringParser(context, result);; }; diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index 0e2c31b69..67a00ab24 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -33,9 +33,9 @@ namespace System.Management.Automation.Language internal const BindingFlags instancePublicFlags = BindingFlags.Instance | BindingFlags.Public; internal static readonly ConstructorInfo ObjectList_ctor = - typeof(List).GetConstructor(PSTypeExtensions.EmptyTypes); + typeof(List).GetConstructor(Type.EmptyTypes); internal static readonly MethodInfo ObjectList_ToArray = - typeof(List).GetMethod(nameof(List.ToArray), PSTypeExtensions.EmptyTypes); + typeof(List).GetMethod(nameof(List.ToArray), Type.EmptyTypes); internal static readonly MethodInfo ArrayOps_GetMDArrayValue = typeof(ArrayOps).GetMethod(nameof(ArrayOps.GetMDArrayValue), staticFlags); @@ -778,7 +778,7 @@ namespace System.Management.Automation.Language private IEnumerable CompileInvocationArguments(IEnumerable arguments) { - return arguments == null ? Utils.EmptyArray() : arguments.Select(CompileExpressionOperand); + return arguments == null ? Array.Empty() : arguments.Select(CompileExpressionOperand); } internal Expression ReduceAssignment(ISupportsAssignment left, TokenKind tokenKind, Expression right) @@ -1266,7 +1266,7 @@ namespace System.Management.Automation.Language OutputTypeAttribute result; if (ast.PositionalArguments.Count == 0) { - result = new OutputTypeAttribute(Utils.EmptyArray()); + result = new OutputTypeAttribute(Array.Empty()); } else if (ast.PositionalArguments.Count == 1) { @@ -3726,7 +3726,7 @@ namespace System.Management.Automation.Language internal static Expression CreateThrow(Type resultType, Type exception, params object[] exceptionArgs) { - Type[] argTypes = PSTypeExtensions.EmptyTypes; + Type[] argTypes = Type.EmptyTypes; if (exceptionArgs != null) { argTypes = new Type[exceptionArgs.Length]; @@ -5914,7 +5914,7 @@ namespace System.Management.Automation.Language } return InvokeMemberExpressionAst.Arguments == null - ? Utils.EmptyArray() + ? Array.Empty() : (InvokeMemberExpressionAst.Arguments.Select(compiler.Compile)).ToArray(); } diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index 64224f3e8..50ed92dba 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -19,7 +19,7 @@ namespace System.Management.Automation.Language private static int s_globalCounter = 0; private static readonly CustomAttributeBuilder s_hiddenCustomAttributeBuilder = - new CustomAttributeBuilder(typeof(HiddenAttribute).GetConstructor(Type.EmptyTypes), Utils.EmptyArray()); + new CustomAttributeBuilder(typeof(HiddenAttribute).GetConstructor(Type.EmptyTypes), Array.Empty()); private static readonly string s_sessionStateKeeperFieldName = "__sessionStateKeeper"; internal static readonly string SessionStateFieldName = "__sessionState"; @@ -765,7 +765,7 @@ namespace System.Management.Automation.Language var parameters = ((IParameterMetadataProvider)functionMemberAst).Parameters; if (parameters == null) { - return PSTypeExtensions.EmptyTypes; + return Type.EmptyTypes; } bool anyErrors = false; @@ -1279,7 +1279,7 @@ namespace System.Management.Automation.Language private static IEnumerable GetAssemblyAttributeBuilders(string scriptFile) { var ctor = typeof(DynamicClassImplementationAssemblyAttribute).GetConstructor(Type.EmptyTypes); - var emptyArgs = Utils.EmptyArray(); + var emptyArgs = Array.Empty(); if (string.IsNullOrEmpty(scriptFile)) { yield return new CustomAttributeBuilder(ctor, emptyArgs); @@ -1291,7 +1291,7 @@ namespace System.Management.Automation.Language var propertyArgs = new object[] { scriptFile }; yield return new CustomAttributeBuilder(ctor, emptyArgs, - propertyInfo, propertyArgs, Utils.EmptyArray(), emptyArgs); + propertyInfo, propertyArgs, Array.Empty(), emptyArgs); } diff --git a/src/System.Management.Automation/engine/parser/Parser.cs b/src/System.Management.Automation/engine/parser/Parser.cs index d3ed32458..ea265b711 100644 --- a/src/System.Management.Automation/engine/parser/Parser.cs +++ b/src/System.Management.Automation/engine/parser/Parser.cs @@ -88,7 +88,7 @@ namespace System.Management.Automation.Language var emptyExtent = new EmptyScriptExtent(); var errorMsg = string.Format(CultureInfo.CurrentCulture, ParserStrings.FileReadError, e.Message); errors = new[] { new ParseError(emptyExtent, "FileReadError", errorMsg) }; - tokens = Utils.EmptyArray(); + tokens = Array.Empty(); return new ScriptBlockAst(emptyExtent, null, new StatementBlockAst(emptyExtent, null, null), false); } @@ -1792,7 +1792,7 @@ namespace System.Management.Automation.Language nameof(ParserStrings.MissingNamedStatementBlock), ParserStrings.MissingNamedStatementBlock, blockNameToken.Kind.Text()); - statementBlock = new StatementBlockAst(blockNameToken.Extent, Utils.EmptyArray(), null); + statementBlock = new StatementBlockAst(blockNameToken.Extent, Array.Empty(), null); } else { diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index 96c7bdb32..31ce46f38 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -124,7 +124,7 @@ namespace System.Management.Automation internal class TypeInferenceContext { - public static readonly PSTypeName[] EmptyPSTypeNameArray = Utils.EmptyArray(); + public static readonly PSTypeName[] EmptyPSTypeNameArray = Array.Empty(); private readonly PowerShell _powerShell; public TypeInferenceContext() @@ -1496,13 +1496,13 @@ namespace System.Management.Automation var memberAsStringConst = memberCommandElement as StringConstantExpressionAst; if (memberAsStringConst == null) { - return Utils.EmptyArray(); + return Array.Empty(); } var exprType = GetExpressionType(expression, isStatic); if (exprType == null || exprType.Length == 0) { - return Utils.EmptyArray(); + return Array.Empty(); } var res = new List(10); diff --git a/src/System.Management.Automation/engine/parser/TypeResolver.cs b/src/System.Management.Automation/engine/parser/TypeResolver.cs index 70e22357f..102295070 100644 --- a/src/System.Management.Automation/engine/parser/TypeResolver.cs +++ b/src/System.Management.Automation/engine/parser/TypeResolver.cs @@ -518,7 +518,7 @@ namespace System.Management.Automation.Language internal class TypeResolutionState { internal static readonly string[] systemNamespace = { "System" }; - internal static readonly Assembly[] emptyAssemblies = Utils.EmptyArray(); + internal static readonly Assembly[] emptyAssemblies = Array.Empty(); internal static readonly TypeResolutionState UsingSystem = new TypeResolutionState(); internal readonly string[] namespaces; diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index 1cb699adf..dd5504c59 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -286,7 +286,7 @@ namespace System.Management.Automation.Language internal abstract object Accept(ICustomAstVisitor visitor); internal abstract AstVisitAction InternalVisit(AstVisitor visitor); - internal static PSTypeName[] EmptyPSTypeNameArray = Utils.EmptyArray(); + internal static PSTypeName[] EmptyPSTypeNameArray = Array.Empty(); internal bool IsInWorkflow() { @@ -3458,7 +3458,7 @@ namespace System.Management.Automation.Language StatementAst statement = null; if (type == SpecialMemberFunctionType.DefaultConstructor) { - var invokeMemberAst = new BaseCtorInvokeMemberExpressionAst(extent, extent, Utils.EmptyArray()); + var invokeMemberAst = new BaseCtorInvokeMemberExpressionAst(extent, extent, Array.Empty()); statement = new CommandExpressionAst(extent, invokeMemberAst, null); } @@ -3975,7 +3975,7 @@ namespace System.Management.Automation.Language /// public class DataStatementAst : StatementAst { - private static readonly ExpressionAst[] s_emptyCommandsAllowed = Utils.EmptyArray(); + private static readonly ExpressionAst[] s_emptyCommandsAllowed = Array.Empty(); /// /// Construct a data statement. @@ -4604,7 +4604,7 @@ namespace System.Management.Automation.Language /// public class SwitchStatementAst : LabeledStatementAst { - private static readonly SwitchClause[] s_emptyClauseArray = Utils.EmptyArray(); + private static readonly SwitchClause[] s_emptyClauseArray = Array.Empty(); /// /// Construct a switch statement. diff --git a/src/System.Management.Automation/engine/regex.cs b/src/System.Management.Automation/engine/regex.cs index e5af675f8..238cf2cbc 100644 --- a/src/System.Management.Automation/engine/regex.cs +++ b/src/System.Management.Automation/engine/regex.cs @@ -235,7 +235,7 @@ namespace System.Management.Automation /// public static string Escape(string pattern) { - return Escape(pattern, Utils.EmptyArray()); + return Escape(pattern, Array.Empty()); } /// diff --git a/src/System.Management.Automation/engine/remoting/client/JobManager.cs b/src/System.Management.Automation/engine/remoting/client/JobManager.cs index 65b9ac000..b2949f305 100644 --- a/src/System.Management.Automation/engine/remoting/client/JobManager.cs +++ b/src/System.Management.Automation/engine/remoting/client/JobManager.cs @@ -87,7 +87,7 @@ namespace System.Management.Automation } else { - ConstructorInfo constructor = jobSourceAdapterType.GetConstructor(PSTypeExtensions.EmptyTypes); + ConstructorInfo constructor = jobSourceAdapterType.GetConstructor(Type.EmptyTypes); if (!constructor.IsPublic) { string message = string.Format(CultureInfo.CurrentCulture, diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs index fc1eb5024..fcfeb4384 100644 --- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs +++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs @@ -599,7 +599,7 @@ else useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { file, @@ -1216,7 +1216,7 @@ else if (sessionType == PSSessionType.Workflow) { - List modifiedModulePath = new List(modulesToImport ?? Utils.EmptyArray()); + List modifiedModulePath = new List(modulesToImport ?? Array.Empty()); modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE); modulesToImport = modifiedModulePath.ToArray(); } @@ -1339,7 +1339,7 @@ else cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.RestartWSManServiceMessageV)); ScriptBlock restartServiceScript = cmdlet.InvokeCommand.NewScriptBlock(restartWSManFormat); - var emptyArray = Utils.EmptyArray(); + var emptyArray = Array.Empty(); restartServiceScript.InvokeUsingCmdlet( contextCmdlet: cmdlet, useLocalScope: true, @@ -2697,7 +2697,7 @@ else useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { Name, @@ -2959,7 +2959,7 @@ $args[0] | ForEach-Object {{ useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { arguments, @@ -3533,7 +3533,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { propertiesToUpdate, @@ -3629,7 +3629,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { runAsCredential.UserName, @@ -3700,7 +3700,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { maxIdleTimeOut, idleTimeOut, setMaxIdleTimeoutFirst }); @@ -3715,7 +3715,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { quotas, }); } @@ -3756,7 +3756,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { optionsTable, @@ -3862,7 +3862,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { encodedSessionConfigData, @@ -4525,7 +4525,7 @@ $_ | Enable-PSSessionConfiguration -force $args[0] -sddl $args[1] -isSDDLSpecifi useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: _shellsToEnable, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { _force, @@ -4546,7 +4546,7 @@ $_ | Enable-PSSessionConfiguration -force $args[0] -sddl $args[1] -isSDDLSpecifi System.Management.Automation.Tracing.Tracer tracer = new System.Management.Automation.Tracing.Tracer(); StringBuilder sb = new StringBuilder(); - foreach (string endPointName in Name ?? Utils.EmptyArray()) + foreach (string endPointName in Name ?? Array.Empty()) { sb.Append(endPointName); sb.Append(", "); @@ -4760,7 +4760,7 @@ $_ | Disable-PSSessionConfiguration -force $args[0] -whatif:$args[1] -confirm:$a useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: _shellsToDisable, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { _force, @@ -4774,7 +4774,7 @@ $_ | Disable-PSSessionConfiguration -force $args[0] -whatif:$args[1] -confirm:$a System.Management.Automation.Tracing.Tracer tracer = new System.Management.Automation.Tracing.Tracer(); StringBuilder sb = new StringBuilder(); - foreach (string endPointName in Name ?? Utils.EmptyArray()) + foreach (string endPointName in Name ?? Array.Empty()) { sb.Append(endPointName); sb.Append(", "); @@ -5240,7 +5240,7 @@ Enable-PSRemoting -force $args[0] -queryForRegisterDefault $args[1] -captionForR useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { _force, @@ -5444,7 +5444,7 @@ Disable-PSRemoting -force:$args[0] -queryForSet $args[1] -captionForSet $args[2] useLocalScope: true, errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, dollarUnder: AutomationNull.Value, - input: Utils.EmptyArray(), + input: Array.Empty(), scriptThis: AutomationNull.Value, args: new object[] { _force, diff --git a/src/System.Management.Automation/engine/remoting/commands/NewPSSessionConfigurationFile.cs b/src/System.Management.Automation/engine/remoting/commands/NewPSSessionConfigurationFile.cs index ff1a078fc..25c491180 100644 --- a/src/System.Management.Automation/engine/remoting/commands/NewPSSessionConfigurationFile.cs +++ b/src/System.Management.Automation/engine/remoting/commands/NewPSSessionConfigurationFile.cs @@ -269,7 +269,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _scriptsToProcess = Utils.EmptyArray(); + private string[] _scriptsToProcess = Array.Empty(); /// /// Role definitions for this session configuration (Role name -> Role capability) @@ -402,7 +402,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleAliases = Utils.EmptyArray(); + private string[] _visibleAliases = Array.Empty(); /// /// A list of visible cmdlets. @@ -462,7 +462,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleExternalCommands = Utils.EmptyArray(); + private string[] _visibleExternalCommands = Array.Empty(); /// /// A list of providers. @@ -482,7 +482,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleProviders = Utils.EmptyArray(); + private string[] _visibleProviders = Array.Empty(); /// /// A list of aliases. @@ -583,7 +583,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _typesToProcess = Utils.EmptyArray(); + private string[] _typesToProcess = Array.Empty(); /// /// A list of format data to process. @@ -603,7 +603,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _formatsToProcess = Utils.EmptyArray(); + private string[] _formatsToProcess = Array.Empty(); /// /// A list of assemblies to load. @@ -1291,7 +1291,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleAliases = Utils.EmptyArray(); + private string[] _visibleAliases = Array.Empty(); /// /// A list of visible cmdlets. @@ -1351,7 +1351,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleExternalCommands = Utils.EmptyArray(); + private string[] _visibleExternalCommands = Array.Empty(); /// /// A list of providers. @@ -1371,7 +1371,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _visibleProviders = Utils.EmptyArray(); + private string[] _visibleProviders = Array.Empty(); /// /// Scripts to process. @@ -1391,7 +1391,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _scriptsToProcess = Utils.EmptyArray(); + private string[] _scriptsToProcess = Array.Empty(); /// /// A list of aliases. @@ -1492,7 +1492,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _typesToProcess = Utils.EmptyArray(); + private string[] _typesToProcess = Array.Empty(); /// /// A list of format data to process. @@ -1512,7 +1512,7 @@ namespace Microsoft.PowerShell.Commands } } - private string[] _formatsToProcess = Utils.EmptyArray(); + private string[] _formatsToProcess = Array.Empty(); /// /// A list of assemblies to load. diff --git a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs index 5f2ba937d..63661d45c 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs @@ -70,7 +70,7 @@ namespace Microsoft.PowerShell.Commands } else if (computerNames.Length == 0) { - resolvedComputerNames = Utils.EmptyArray(); + resolvedComputerNames = Array.Empty(); } else { diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs index e31d1120a..304e6b817 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs @@ -130,7 +130,7 @@ namespace System.Management.Automation.Remoting // ignore it and dont try to serialize again. if (e != null) { - _timeZoneInByteFormat = Utils.EmptyArray(); + _timeZoneInByteFormat = Array.Empty(); } } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs index 0b317f251..9909920d2 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs @@ -804,7 +804,7 @@ namespace System.Management.Automation.Remoting.Client if (this.Type == (uint)WSManDataType.WSMAN_DATA_TYPE_BINARY) return _data; else - return Utils.EmptyArray(); + return Array.Empty(); } } diff --git a/src/System.Management.Automation/engine/remoting/server/ServerMethodExecutor.cs b/src/System.Management.Automation/engine/remoting/server/ServerMethodExecutor.cs index 044931792..1dd6ecc92 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerMethodExecutor.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerMethodExecutor.cs @@ -80,7 +80,7 @@ namespace System.Management.Automation.Remoting /// internal void ExecuteVoidMethod(RemoteHostMethodId methodId) { - ExecuteVoidMethod(methodId, Utils.EmptyArray()); + ExecuteVoidMethod(methodId, Array.Empty()); } /// @@ -111,7 +111,7 @@ namespace System.Management.Automation.Remoting /// internal T ExecuteMethod(RemoteHostMethodId methodId) { - return ExecuteMethod(methodId, Utils.EmptyArray()); + return ExecuteMethod(methodId, Array.Empty()); } /// diff --git a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs index 81156098b..18d9449a5 100644 --- a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs +++ b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs @@ -585,7 +585,7 @@ namespace System.Management.Automation.Language if (target.Value == AutomationNull.Value) { return new DynamicMetaObject( - Expression.Call(Expression.Constant(Utils.EmptyArray()), typeof(Array).GetMethod("GetEnumerator")), + Expression.Call(Expression.Constant(Array.Empty()), typeof(Array).GetMethod("GetEnumerator")), BindingRestrictions.GetInstanceRestriction(target.Expression, AutomationNull.Value)).WriteToDebugLog(this); } @@ -726,7 +726,7 @@ namespace System.Management.Automation.Language private static IEnumerator AutomationNullRule(CallSite site, object obj) { return obj == AutomationNull.Value - ? Utils.EmptyArray().GetEnumerator() + ? Array.Empty().GetEnumerator() : ((CallSite>)site).Update(site, obj); } @@ -805,7 +805,7 @@ namespace System.Management.Automation.Language if (target.Value == AutomationNull.Value) { - return new DynamicMetaObject(Expression.Constant(Utils.EmptyArray()), + return new DynamicMetaObject(Expression.Constant(Array.Empty()), BindingRestrictions.GetInstanceRestriction(target.Expression, AutomationNull.Value)).WriteToDebugLog(this); } @@ -874,7 +874,7 @@ namespace System.Management.Automation.Language var enumerable = PSEnumerableBinder.IsEnumerable(target); if (enumerable == null) { - var bindingResult = PSVariableAssignmentBinder.Get().Bind(target, Utils.EmptyArray()); + var bindingResult = PSVariableAssignmentBinder.Get().Bind(target, Array.Empty()); var restrictions = target.LimitType.IsValueType ? bindingResult.Restrictions : target.PSGetTypeRestriction(); @@ -3706,7 +3706,7 @@ namespace System.Management.Automation.Language } return errorSuggestion ?? target.ThrowRuntimeError( - Utils.EmptyArray(), + Array.Empty(), BindingRestrictions.Empty, "OperatorRequiresNumber", ParserStrings.OperatorRequiresNumber, @@ -7435,7 +7435,7 @@ namespace System.Management.Automation.Language if (string.Equals(methodName, "Foreach", StringComparison.OrdinalIgnoreCase)) { var enumerator = (new object[] { obj }).GetEnumerator(); - return EnumerableOps.ForEach(enumerator, args[0], Utils.EmptyArray()); + return EnumerableOps.ForEach(enumerator, args[0], Array.Empty()); } throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), null, diff --git a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs index 619f1112e..337d2a5a5 100644 --- a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs +++ b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs @@ -96,7 +96,7 @@ namespace System.Management.Automation CmdletBindingAttribute cmdletBindingAttribute = null; if (!Ast.HasAnyScriptBlockAttributes()) { - attributes = Utils.EmptyArray(); + attributes = Array.Empty(); } else { @@ -963,7 +963,7 @@ namespace System.Management.Automation if (args == null) { - args = Utils.EmptyArray(); + args = Array.Empty(); } bool runOptimized = context._debuggingMode > 0 ? false : createLocalScope; @@ -1289,7 +1289,7 @@ namespace System.Management.Automation var leftOverArgs = args.Length - parameters.Length; if (leftOverArgs <= 0) { - return Utils.EmptyArray(); + return Array.Empty(); } object[] result = new object[leftOverArgs]; diff --git a/src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs b/src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs index df2e604b4..076a59b57 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs @@ -99,7 +99,7 @@ namespace System.Management.Automation.Internal public class ScriptBlockMemberMethodWrapper { /// Used in codegen - public static readonly object[] _emptyArgumentArray = Utils.EmptyArray(); // See TypeDefiner.DefineTypeHelper.DefineMethodBody + public static readonly object[] _emptyArgumentArray = Array.Empty(); // See TypeDefiner.DefineTypeHelper.DefineMethodBody /// /// Indicate the wrapper is for a static member method. diff --git a/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs b/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs index b68f37431..3a26e8eec 100644 --- a/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs +++ b/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs @@ -228,7 +228,7 @@ namespace System.Management.Automation if (args == null) { - args = Utils.EmptyArray(); + args = Array.Empty(); } // Perform validations on the ScriptBlock. GetSimplePipeline can allow for more than one diff --git a/src/System.Management.Automation/help/HelpInfo.cs b/src/System.Management.Automation/help/HelpInfo.cs index b9e166043..e8dbc08d9 100644 --- a/src/System.Management.Automation/help/HelpInfo.cs +++ b/src/System.Management.Automation/help/HelpInfo.cs @@ -146,7 +146,7 @@ namespace System.Management.Automation /// internal virtual PSObject[] GetParameter(string pattern) { - return new PSObject[0]; + return Array.Empty(); } /// diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index 4357fd03d..bc3dfd769 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -3116,7 +3116,7 @@ namespace Microsoft.PowerShell.Commands case RegistryValueKind.Binary: case RegistryValueKind.Unknown: { - defaultValue = new byte[0]; + defaultValue = Array.Empty(); } break; @@ -3135,7 +3135,7 @@ namespace Microsoft.PowerShell.Commands break; case RegistryValueKind.MultiString: { - defaultValue = new string[0]; + defaultValue = Array.Empty(); } break; diff --git a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs index 38334142a..b858651ee 100644 --- a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs +++ b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs @@ -436,7 +436,7 @@ namespace System.Management.Automation get { return _missingPSSnapIns; } } - private ReadOnlyCollection _missingPSSnapIns = new ReadOnlyCollection(new string[0]); + private ReadOnlyCollection _missingPSSnapIns = new ReadOnlyCollection(Array.Empty()); /// /// Gets or sets the ID of the shell. diff --git a/src/System.Management.Automation/utils/ExtensionMethods.cs b/src/System.Management.Automation/utils/ExtensionMethods.cs index fa520da3c..a7abaf710 100644 --- a/src/System.Management.Automation/utils/ExtensionMethods.cs +++ b/src/System.Management.Automation/utils/ExtensionMethods.cs @@ -70,11 +70,6 @@ namespace System.Management.Automation /// internal static partial class PSTypeExtensions { - /// - /// Type.EmptyTypes is not in CoreCLR. Use this one to replace it. - /// - internal static Type[] EmptyTypes = new Type[0]; - /// /// Check does the type have an instance default constructor with visibility that allows calling it from subclass. /// diff --git a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs index 780a20eee..78b92409f 100644 --- a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs +++ b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs @@ -487,12 +487,12 @@ namespace System.Management.Automation #region private private string _resourceString; - private object[] _args = new object[0]; + private object[] _args = Array.Empty(); private string _commandName; private string BuildMessage() { - object[] messageArgs = new object[0]; + object[] messageArgs = Array.Empty(); if (_args != null) { diff --git a/src/System.Management.Automation/utils/StructuredTraceSource.cs b/src/System.Management.Automation/utils/StructuredTraceSource.cs index b7d85b2ad..8fa7ee771 100644 --- a/src/System.Management.Automation/utils/StructuredTraceSource.cs +++ b/src/System.Management.Automation/utils/StructuredTraceSource.cs @@ -903,7 +903,7 @@ namespace System.Management.Automation PSTraceSourceOptions.WriteLine, writeLineFormatter, format, - Utils.EmptyArray()); + Array.Empty()); } }