From 22d2273ce4f6ec92bad6aca1e1ef47984d6b237c Mon Sep 17 00:00:00 2001 From: PowerShell Team Date: Tue, 2 Aug 2016 22:25:13 -0700 Subject: [PATCH] Refactoring - use ?? in more places --- .../cmdletization/SessionBasedWrapper.cs | 9 +- .../cmdletization/cim/cimWrapper.cs | 9 +- .../commands/management/Navigation.cs | 19 +--- .../management/RemovePropertyCommand.cs | 32 ++----- .../commands/management/Service.cs | 4 +- .../commands/utility/AddType.cs | 12 +-- .../commands/utility/CustomSerialization.cs | 3 +- .../commands/utility/ExportAliasCommand.cs | 39 +------- .../commands/utility/GetAliasCommand.cs | 62 ++----------- .../commands/utility/GetMember.cs | 6 +- .../commands/utility/MatchString.cs | 6 +- .../WebCmdlet/WebCmdletElementCollection.cs | 6 +- .../commands/utility/WriteConsoleCmdlet.cs | 6 +- .../host/msh/ConsoleHost.cs | 4 +- .../DscSupport/CimDSCParser.cs | 16 +--- .../common/BaseOutputtingCommand.cs | 4 +- .../displayResourceManagerCache.cs | 8 +- .../FormatAndOutput/common/ILineOutput.cs | 2 +- .../FormatAndOutput/common/TableWriter.cs | 5 +- .../common/Utilities/MshObjectUtil.cs | 7 +- .../engine/CmdletInfo.cs | 10 +- .../engine/CmdletParameterBinderController.cs | 7 +- .../engine/ComInterop/ComInvokeBinder.cs | 10 +- .../engine/ComInterop/TypeUtils.cs | 7 +- .../engine/CommandBase.cs | 16 +--- .../CommandCompletion/CompletionCompleters.cs | 7 +- .../engine/CommandDiscovery.cs | 15 +-- .../engine/CommandInfo.cs | 10 +- .../engine/CoreAdapter.cs | 6 +- .../engine/EngineIntrinsics.cs | 9 +- .../engine/ErrorPackage.cs | 13 +-- .../engine/EventManager.cs | 8 +- .../engine/ExecutionContext.cs | 21 +---- .../engine/InitialSessionState.cs | 11 +-- .../engine/InvocationInfo.cs | 20 +--- .../engine/LanguagePrimitives.cs | 19 +--- .../engine/ManagementObjectAdapter.cs | 6 +- .../engine/Modules/NewModuleCommand.cs | 6 +- .../engine/Modules/PSModuleInfo.cs | 9 +- .../engine/MshCmdlet.cs | 6 +- .../engine/MshCommandRuntime.cs | 40 +------- .../engine/MshMemberInfo.cs | 4 +- .../engine/MshObject.cs | 19 +--- .../engine/MshObjectTypeDescriptor.cs | 7 +- .../engine/NativeCommandProcessor.cs | 7 +- .../Serialization/InternalMISerializer.cs | 10 +- .../engine/ParameterBinderBase.cs | 11 +-- .../engine/PathInterfaces.cs | 6 +- .../engine/ProxyCommand.cs | 13 +-- .../engine/SessionState.cs | 32 +------ .../engine/SessionStateFunctionAPIs.cs | 7 +- .../engine/SessionStatePublic.cs | 59 +++--------- .../engine/SessionStateScope.cs | 20 +--- ...SessionStateSecurityDescriptorInterface.cs | 15 +-- .../engine/SessionStateVariableAPIs.cs | 14 +-- .../engine/ShellVariable.cs | 36 +------- .../engine/hostifaces/ConnectionBase.cs | 6 +- .../engine/hostifaces/FieldDescription.cs | 11 +-- .../engine/hostifaces/InternalHost.cs | 7 +- .../engine/hostifaces/ListModifier.cs | 4 +- .../engine/hostifaces/PowerShell.cs | 9 +- .../hostifaces/PowerShellProcessInstance.cs | 5 - .../interpreter/ControlFlowInstructions.cs | 27 +----- .../engine/lang/parserutils.cs | 9 +- .../engine/parser/PSType.cs | 7 +- .../engine/remoting/client/Job.cs | 2 +- .../remoting/client/PowerShellStreams.cs | 9 +- .../client/RemoteRunspacePoolInternal.cs | 13 +-- .../engine/remoting/client/remoterunspace.cs | 6 +- .../remoting/commands/ConnectPSSession.cs | 2 +- .../remoting/commands/DisconnectPSSession.cs | 6 +- .../common/WireDataFormat/EncodeAndDecode.cs | 7 +- .../engine/serialization.cs | 28 ++---- .../help/UpdatableHelpCommandBase.cs | 15 +-- .../minishell/api/RunspaceConfiguration.cs | 91 ++++--------------- .../namespaces/SessionStateProviderBase.cs | 6 +- .../security/SecureStringHelper.cs | 11 +-- .../singleshell/Commands/MshSnapinCommands.cs | 9 +- .../config/RunspaceConfigForSingleShell.cs | 31 ++----- .../singleshell/installer/CustomMshSnapin.cs | 40 +------- .../installer/MshSnapinInstaller.cs | 8 +- .../utils/ExecutionExceptions.cs | 10 +- .../utils/ObjectStream.cs | 7 +- .../utils/ParameterBinderExceptions.cs | 9 +- .../utils/StructuredTraceSource.cs | 9 +- .../utils/WindowsErrorReporting.cs | 6 +- .../perfCounters/CounterSetRegistrarBase.cs | 9 +- .../utils/perfCounters/PSPerfCountersMgr.cs | 9 +- 88 files changed, 231 insertions(+), 972 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs index 314976161..b81fc370b 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs @@ -75,14 +75,7 @@ namespace Microsoft.PowerShell.Cmdletization [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] protected TSession[] Session { - get - { - if (_session == null) - { - _session = new TSession[] { this.DefaultSession }; - } - return _session; - } + get { return _session ?? (_session = new TSession[] {this.DefaultSession}); } set { if (value == null) diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs index 9e86a3b84..bc5e3b48a 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs @@ -90,14 +90,11 @@ namespace Microsoft.PowerShell.Cmdletization.Cim { get { - if (_cmdletInvocationContext == null) - { - _cmdletInvocationContext = new CimCmdletInvocationContext( + return _cmdletInvocationContext ?? + (_cmdletInvocationContext = new CimCmdletInvocationContext( this.CmdletDefinitionContext, this.Cmdlet, - this.GetDynamicNamespace()); - } - return _cmdletInvocationContext; + this.GetDynamicNamespace())); } } private CimCmdletInvocationContext _cmdletInvocationContext; diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index f4a206d16..1daab675a 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -4754,22 +4754,9 @@ namespace Microsoft.PowerShell.Commands [Parameter(Position = 0, ValueFromPipelineByPropertyName = true)] public string[] PSProvider { - get - { - return _provider; - } - set - { - if (value == null) - { - _provider = new string[0]; - } - else - { - _provider = value; - } - } - } // Provider + get { return _provider; } + set { _provider = value ?? Utils.EmptyArray(); } + } #endregion Command parameters diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs index 9bb05626d..708a9744c 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/RemovePropertyCommand.cs @@ -62,23 +62,9 @@ namespace Microsoft.PowerShell.Commands [Alias("PSProperty")] public string[] Name { - get - { - return _property; - } // get - - set - { - if (value == null) - { - _property = new string[0]; - } - else - { - _property = value; - } - } - } // Property + get { return _property; } + set { _property = value ?? Utils.EmptyArray(); } + } /// /// Gets or sets the force property @@ -97,15 +83,9 @@ namespace Microsoft.PowerShell.Commands [Parameter] public override SwitchParameter Force { - get - { - return base.Force; - } - set - { - base.Force = value; - } - } // Force + get { return base.Force; } + set { base.Force = value; } + } /// /// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs index e22c17107..5e1cfedcf 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs @@ -1976,9 +1976,7 @@ namespace Microsoft.PowerShell.Commands // confirm the operation first // this is always false if WhatIf is set - if (!ShouldProcessServiceOperation( - (null == DisplayName) ? "" : DisplayName, - Name)) + if (!ShouldProcessServiceOperation(DisplayName ?? "", Name)) { return; } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index ccfe96f48..37fb31baf 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -449,18 +449,10 @@ namespace Microsoft.PowerShell.Commands [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public String[] ReferencedAssemblies { - get - { - return referencedAssemblies; - } + get { return referencedAssemblies; } set { - if (value == null) - referencedAssemblies = Utils.EmptyArray(); - else - { - referencedAssemblies = value; - } + referencedAssemblies = value ?? Utils.EmptyArray(); referencedAssembliesSpecified = true; } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs index b4d8d3590..41b9e1071 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs @@ -376,8 +376,7 @@ namespace System.Management.Automation if (ct == ContainerType.None) return false; - WriteStartOfPSObject(mshSource != null ? mshSource : PSObject.AsPSObject(source), - property, true); + WriteStartOfPSObject(mshSource ?? PSObject.AsPSObject(source), property, true); switch (ct) { case ContainerType.Dictionary: diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs index cc7a4f1d4..b8f7f738a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs @@ -51,21 +51,8 @@ namespace Microsoft.PowerShell.Commands [Parameter(Mandatory = true, Position = 0, ParameterSetName = "ByPath")] public string Path { - get - { - return _path; - } - set - { - if (value == null) - { - _path = "."; - } - else - { - _path = value; - } - } + get { return _path; } + set { _path = value ?? "."; } } private string _path = "."; @@ -77,10 +64,7 @@ namespace Microsoft.PowerShell.Commands [Alias("PSPath")] public string LiteralPath { - get - { - return _path; - } + get { return _path; } set { if (value == null) @@ -103,21 +87,8 @@ namespace Microsoft.PowerShell.Commands [Parameter(Position = 1, ValueFromPipelineByPropertyName = true)] public string[] Name { - get - { - return _names; - } - set - { - if (value == null) - { - _names = new string[] { "*" }; - } - else - { - _names = value; - } - } + get { return _names; } + set { _names = value ?? new string[] { "*" }; } } private string[] _names = new string[] { "*" }; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs index ab2f292b0..6870cf023 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetAliasCommand.cs @@ -28,21 +28,8 @@ namespace Microsoft.PowerShell.Commands [Parameter(ParameterSetName = "Default", Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] public string[] Name { - get - { - return _names; - } - set - { - if (value == null) - { - _names = new string[] { "*" }; - } - else - { - _names = value; - } - } + get { return _names; } + set { _names = value ?? new string[] { "*" }; } } private string[] _names = new string[] { "*" }; @@ -53,21 +40,8 @@ namespace Microsoft.PowerShell.Commands [Parameter] public string[] Exclude { - get - { - return _excludes; - } - set - { - if (value == null) - { - _excludes = new string[0]; - } - else - { - _excludes = value; - } - } + get { return _excludes; } + set { _excludes = value ?? new string[0]; } } private string[] _excludes = new string[0]; @@ -77,19 +51,7 @@ namespace Microsoft.PowerShell.Commands /// /// [Parameter] - public string Scope - { - get - { - return _scope; - } - - set - { - _scope = value; - } - } - private string _scope; + public string Scope { get; set; } /// /// Parameter definition to retrieve aliases based on their definitions. @@ -97,13 +59,7 @@ namespace Microsoft.PowerShell.Commands [Parameter(ParameterSetName = "Definition")] [ValidateNotNullOrEmpty] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public String[] Definition - { - get { return _definition; } - set { _definition = value; } - } - private string[] _definition; - + public String[] Definition { get; set; } #endregion Parameters @@ -117,7 +73,7 @@ namespace Microsoft.PowerShell.Commands { if (ParameterSetName.Equals("Definition")) { - foreach (string defn in _definition) + foreach (string defn in Definition) { WriteMatches(defn, "Definition"); } @@ -140,13 +96,13 @@ namespace Microsoft.PowerShell.Commands //get the command origin CommandOrigin origin = MyInvocation.CommandOrigin; string displayString = "name"; - if (!String.IsNullOrEmpty(_scope)) + if (!String.IsNullOrEmpty(Scope)) { // This can throw PSArgumentException and PSArgumentOutOfRangeException // but just let them go as this is terminal for the pipeline and the // exceptions are already properly adorned with an ErrorRecord. - aliasTable = SessionState.Internal.GetAliasTableAtScope(_scope); + aliasTable = SessionState.Internal.GetAliasTableAtScope(Scope); } else { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs index cefb6ac2d..5b76bf169 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs @@ -154,11 +154,7 @@ namespace Microsoft.PowerShell.Commands { staticAdapter = PSObject.dotNetStaticAdapter; object baseObject = this.InputObject.BaseObject; - baseObjectAsType = baseObject as System.Type; - if (baseObjectAsType == null) - { - baseObjectAsType = baseObject.GetType(); - } + baseObjectAsType = baseObject as System.Type ?? baseObject.GetType(); typeName = baseObjectAsType.FullName; } else diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs index e65b0deec..ad29ef9a1 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs @@ -114,9 +114,7 @@ namespace Microsoft.PowerShell.Commands { if (!_pathSet) return s_inputStream; - if (_filename == null) - _filename = System.IO.Path.GetFileName(_path); - return _filename; + return _filename ?? (_filename = System.IO.Path.GetFileName(_path)); } } private string _filename; @@ -1714,7 +1712,7 @@ namespace Microsoft.PowerShell.Commands // Matches should be an empty list, rather than null, // in the cases of notMatch and simpleMatch. - matchResult.Matches = (matches != null) ? matches : new Match[] { }; + matchResult.Matches = matches ?? new Match[] { }; return true; } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebCmdletElementCollection.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebCmdletElementCollection.cs index 1c9e6f496..146a0707f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebCmdletElementCollection.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebCmdletElementCollection.cs @@ -26,11 +26,7 @@ namespace Microsoft.PowerShell.Commands public PSObject Find(string nameOrId) { // try Id first - PSObject result = FindById(nameOrId); - if (null == result) - { - result = FindByName(nameOrId); - } + PSObject result = FindById(nameOrId) ?? FindByName(nameOrId); return (result); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs index 945636417..d67284507 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs @@ -127,11 +127,7 @@ namespace Microsoft.PowerShell.Commands /// protected override void ProcessRecord() { - string result = ProcessObject(Object); - if (result == null) - { - result = ""; - } + string result = ProcessObject(Object) ?? ""; HostInformationMessage informationMessage = new HostInformationMessage(); informationMessage.Message = result; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 2aa669c3a..0c99e4767 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -850,9 +850,7 @@ namespace Microsoft.PowerShell get { if (ui == null) return null; - if (_consoleColorProxy == null) - _consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(ui)); - return _consoleColorProxy; + return _consoleColorProxy ?? (_consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(ui))); } } private PSObject _consoleColorProxy; diff --git a/src/System.Management.Automation/DscSupport/CimDSCParser.cs b/src/System.Management.Automation/DscSupport/CimDSCParser.cs index 2a2da8a05..302502507 100644 --- a/src/System.Management.Automation/DscSupport/CimDSCParser.cs +++ b/src/System.Management.Automation/DscSupport/CimDSCParser.cs @@ -642,11 +642,8 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal // Load the base schema files. // ClearCache(); - var dscConfigurationDirectory = Environment.GetEnvironmentVariable("DSC_HOME"); - if (dscConfigurationDirectory == null) - { - dscConfigurationDirectory = "/etc/opt/omi/conf/dsc/configuration"; - } + var dscConfigurationDirectory = Environment.GetEnvironmentVariable("DSC_HOME") ?? + "/etc/opt/omi/conf/dsc/configuration"; Debug.Assert(Directory.Exists(dscConfigurationDirectory), dscConfigurationDirectory + " does not exist."); @@ -3587,12 +3584,9 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal { get { - if (s_cimKeywordImlementationFunction == null) - { - // The scriptblock cache will handle mutual exclusion - s_cimKeywordImlementationFunction = ScriptBlock.Create(CimKeywordImlementationFunctionText); - } - return s_cimKeywordImlementationFunction; + // The scriptblock cache will handle mutual exclusion + return s_cimKeywordImlementationFunction ?? + (s_cimKeywordImlementationFunction = ScriptBlock.Create(CimKeywordImlementationFunctionText)); } } private static ScriptBlock s_cimKeywordImlementationFunction; diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseOutputtingCommand.cs index d105e5ea3..d6887e067 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -958,7 +958,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format int k = 0; foreach (TableColumnInfo tci in this.CurrentTableHeaderInfo.tableColumnInfoList) { - properties[k++] = (tci.label != null) ? tci.label : tci.propertyName; + properties[k++] = tci.label ?? tci.propertyName; } this.Writer.GenerateHeader(properties, this.InnerCommand._lo); } @@ -1042,7 +1042,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format StringCollection props = new StringCollection(); foreach (ListViewField lvf in lve.listViewFieldList) { - props.Add((lvf.label != null) ? lvf.label : lvf.propertyName); + props.Add(lvf.label ?? lvf.propertyName); } if (props.Count == 0) return null; diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/displayResourceManagerCache.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/displayResourceManagerCache.cs index 0df683aac..af1fb3f97 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/displayResourceManagerCache.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/displayResourceManagerCache.cs @@ -159,12 +159,8 @@ namespace Microsoft.PowerShell.Commands.Internal.Format // not found, scan the loaded assemblies // first look for the full name - Assembly retVal = ResolveAssemblyNameInLoadedAssemblies(assemblyName, true); - if (retVal == null) - { - // as a fallback, use the plain name - retVal = ResolveAssemblyNameInLoadedAssemblies(assemblyName, false); - } + Assembly retVal = ResolveAssemblyNameInLoadedAssemblies(assemblyName, true) ?? + ResolveAssemblyNameInLoadedAssemblies(assemblyName, false); // NOTE: we cache the result (both for success and failure) // Porting note: this won't be hit in normal usage, but can be hit with bad build setup diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/ILineOutput.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/ILineOutput.cs index 639ddf1fe..715c48f07 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/ILineOutput.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/ILineOutput.cs @@ -269,7 +269,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format _displayCells = displayCells; _writeLineCall = wlc; - _writeCall = (wc != null) ? wc : wlc; + _writeCall = wc ?? wlc; _lineWrap = lineWrap; } diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/TableWriter.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/TableWriter.cs index a46c7d21b..7cbaa36b3 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/TableWriter.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/TableWriter.cs @@ -358,10 +358,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format private static string GenerateRowField(string val, int width, int alignment, DisplayCells dc) { // make sure the string does not have any embedded in it - string s = StringManipulationHelper.TruncateAtNewLine(val); - - if (s == null) - s = ""; + string s = StringManipulationHelper.TruncateAtNewLine(val) ?? ""; string currentValue = s; int currentValueDisplayLength = dc.Length(currentValue); diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/Utilities/MshObjectUtil.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/Utilities/MshObjectUtil.cs index c170921b6..3e886dcf1 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/Utilities/MshObjectUtil.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/Utilities/MshObjectUtil.cs @@ -516,11 +516,8 @@ namespace Microsoft.PowerShell.Commands.Internal.Format private static MshExpression GetDefaultNameExpression(PSObject so) { - MshExpression retVal = GetDefaultNameExpression(so.PSStandardMembers); - if (retVal == null) - { - retVal = GetDefaultNameExpression(MaskDeserializedAndGetStandardMembers(so)); - } + MshExpression retVal = GetDefaultNameExpression(so.PSStandardMembers) ?? + GetDefaultNameExpression(MaskDeserializedAndGetStandardMembers(so)); return retVal; } diff --git a/src/System.Management.Automation/engine/CmdletInfo.cs b/src/System.Management.Automation/engine/CmdletInfo.cs index 09d9af6c6..87024fe57 100644 --- a/src/System.Management.Automation/engine/CmdletInfo.cs +++ b/src/System.Management.Automation/engine/CmdletInfo.cs @@ -534,13 +534,9 @@ namespace System.Management.Automation /// internal override CommandMetadata CommandMetadata { - get - { - if (_cmdletMetadata == null) - { - _cmdletMetadata = CommandMetadata.Get(this.Name, this.ImplementingType, Context); - } - return _cmdletMetadata; + get { + return _cmdletMetadata ?? + (_cmdletMetadata = CommandMetadata.Get(this.Name, this.ImplementingType, Context)); } } private CommandMetadata _cmdletMetadata; diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs index ab526e521..b9f3cba8f 100644 --- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs +++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs @@ -1383,11 +1383,8 @@ namespace System.Management.Automation // We need to delay binding of this argument to the parameter - DelayedScriptBlockArgument delayedArg = argumentValue as DelayedScriptBlockArgument; - if (delayedArg == null) - { - delayedArg = new DelayedScriptBlockArgument { _argument = argument, _parameterBinder = this }; - } + DelayedScriptBlockArgument delayedArg = argumentValue as DelayedScriptBlockArgument ?? + new DelayedScriptBlockArgument { _argument = argument, _parameterBinder = this }; if (!_delayBindScriptBlocks.ContainsKey(parameter)) { _delayBindScriptBlocks.Add(parameter, delayedArg); diff --git a/src/System.Management.Automation/engine/ComInterop/ComInvokeBinder.cs b/src/System.Management.Automation/engine/ComInterop/ComInvokeBinder.cs index 1f97d2e1b..95d8c078e 100644 --- a/src/System.Management.Automation/engine/ComInterop/ComInvokeBinder.cs +++ b/src/System.Management.Automation/engine/ComInterop/ComInvokeBinder.cs @@ -117,13 +117,9 @@ namespace System.Management.Automation.ComInterop private ParameterExpression ParamVariantsVariable { - get - { - if (_paramVariants == null) - { - _paramVariants = Expression.Variable(VariantArray.GetStructType(_args.Length), "paramVariants"); - } - return _paramVariants; + get { + return _paramVariants ?? + (_paramVariants = Expression.Variable(VariantArray.GetStructType(_args.Length), "paramVariants")); } } diff --git a/src/System.Management.Automation/engine/ComInterop/TypeUtils.cs b/src/System.Management.Automation/engine/ComInterop/TypeUtils.cs index 0401e241b..2d4dc0887 100644 --- a/src/System.Management.Automation/engine/ComInterop/TypeUtils.cs +++ b/src/System.Management.Automation/engine/ComInterop/TypeUtils.cs @@ -108,11 +108,8 @@ namespace System.Management.Automation.ComInterop // try lifted conversion if (nnExprType != convertFrom || nnConvType != convertToType) { - method = FindConversionOperator(eMethods, nnExprType, nnConvType, implicitOnly); - if (method == null) - { - method = FindConversionOperator(cMethods, nnExprType, nnConvType, implicitOnly); - } + method = FindConversionOperator(eMethods, nnExprType, nnConvType, implicitOnly) ?? + FindConversionOperator(cMethods, nnExprType, nnConvType, implicitOnly); if (method != null) { return method; diff --git a/src/System.Management.Automation/engine/CommandBase.cs b/src/System.Management.Automation/engine/CommandBase.cs index a6e450dc7..b3edbcf23 100644 --- a/src/System.Management.Automation/engine/CommandBase.cs +++ b/src/System.Management.Automation/engine/CommandBase.cs @@ -76,15 +76,7 @@ namespace System.Management.Automation.Internal /// The invocation object for this command. internal InvocationInfo MyInvocation { - get - { - if (_myInvocation == null) - { - _myInvocation = new InvocationInfo(this); - } - - return _myInvocation; - } + get { return _myInvocation ?? (_myInvocation = new InvocationInfo(this)); } } /// @@ -448,11 +440,7 @@ namespace System.Management.Automation { using (PSTransactionManager.GetEngineProtectionScope()) { - if (_invokeProvider == null) - { - _invokeProvider = new ProviderIntrinsics(this); - } - return _invokeProvider; + return _invokeProvider ?? (_invokeProvider = new ProviderIntrinsics(this)); } } } // InvokeProvider diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 31c936865..60e7c0b28 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -1876,11 +1876,8 @@ namespace System.Management.Automation { if (argumentValue != null) { - IEnumerable enumerable = LanguagePrimitives.GetEnumerable(argumentValue); - if (enumerable == null) - { - enumerable = new object[] { argumentValue }; - } + IEnumerable enumerable = LanguagePrimitives.GetEnumerable(argumentValue) ?? + new object[] { argumentValue }; foreach (var element in enumerable) { if (element == null) diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 38b45c01c..0b0ac2ee2 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -725,13 +725,10 @@ namespace System.Management.Automation processedAliases.Add(commandInfo.Name); AliasInfo aliasCommandInfo = (AliasInfo)commandInfo; - commandInfo = aliasCommandInfo.ResolvedCommand; + commandInfo = aliasCommandInfo.ResolvedCommand ?? + LookupCommandInfo(aliasCommandInfo.Definition, commandOrigin, Context); // If we didn't have the alias target already resolved, see if it can be loaded. - if (commandInfo == null) - { - commandInfo = LookupCommandInfo(aliasCommandInfo.Definition, commandOrigin, Context); - } if (commandInfo == null) { @@ -1567,13 +1564,7 @@ namespace System.Management.Automation } // Cache the new lookup paths - - if (_cachedLookupPaths == null) - { - _cachedLookupPaths = result; - } - - return _cachedLookupPaths; + return _cachedLookupPaths ?? (_cachedLookupPaths = result); } // GetLookupDirectoryPaths /// diff --git a/src/System.Management.Automation/engine/CommandInfo.cs b/src/System.Management.Automation/engine/CommandInfo.cs index 423d7ab68..8eaa35982 100644 --- a/src/System.Management.Automation/engine/CommandInfo.cs +++ b/src/System.Management.Automation/engine/CommandInfo.cs @@ -601,15 +601,7 @@ namespace System.Management.Automation internal CommandMetadata ExternalCommandMetadata { - get - { - if (_externalCommandMetadata == null) - { - _externalCommandMetadata = new CommandMetadata(this, true); - } - - return _externalCommandMetadata; - } + get { return _externalCommandMetadata ?? (_externalCommandMetadata = new CommandMetadata(this, true)); } set { _externalCommandMetadata = value; } } private CommandMetadata _externalCommandMetadata; diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index c35824255..22383e526 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -669,7 +669,7 @@ namespace System.Management.Automation } catch (TargetInvocationException ex) { - Exception inner = (ex.InnerException == null) ? ex : ex.InnerException; + Exception inner = ex.InnerException ?? ex; throw new GetValueInvocationException("CatchFromBaseAdapterParameterizedPropertyGetValueTI", inner, ExtendedTypeSystem.ExceptionWhenGetting, @@ -3792,7 +3792,7 @@ namespace System.Management.Automation } catch (TargetInvocationException ex) { - Exception inner = (ex.InnerException == null) ? ex : ex.InnerException; + Exception inner = ex.InnerException ?? ex; throw new MethodInvocationException( "DotNetconstructorTargetInvocation", inner, @@ -3844,7 +3844,7 @@ namespace System.Management.Automation if (ex.InnerException is ParameterBindingException) throw ex.InnerException; - Exception inner = (ex.InnerException == null) ? ex : ex.InnerException; + Exception inner = ex.InnerException ?? ex; throw new MethodInvocationException( "DotNetMethodTargetInvocation", diff --git a/src/System.Management.Automation/engine/EngineIntrinsics.cs b/src/System.Management.Automation/engine/EngineIntrinsics.cs index b3b296f9f..cad23c644 100644 --- a/src/System.Management.Automation/engine/EngineIntrinsics.cs +++ b/src/System.Management.Automation/engine/EngineIntrinsics.cs @@ -104,13 +104,8 @@ namespace System.Management.Automation /// public CommandInvocationIntrinsics InvokeCommand { - get - { - if (_invokeCommand == null) - _invokeCommand = new CommandInvocationIntrinsics(_context); - return _invokeCommand; - } - } // InvokeCommand + get { return _invokeCommand ?? (_invokeCommand = new CommandInvocationIntrinsics(_context)); } + } #endregion Public methods diff --git a/src/System.Management.Automation/engine/ErrorPackage.cs b/src/System.Management.Automation/engine/ErrorPackage.cs index ea122bc05..60a536d56 100644 --- a/src/System.Management.Automation/engine/ErrorPackage.cs +++ b/src/System.Management.Automation/engine/ErrorPackage.cs @@ -1307,8 +1307,8 @@ namespace System.Management.Automation } //Get FullyQualifiedErrorId - string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue(serializedErrorRecord, "FullyQualifiedErrorId"); - if (fullyQualifiedErrorId == null) fullyQualifiedErrorId = "fullyQualifiedErrorId"; + string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue(serializedErrorRecord, "FullyQualifiedErrorId") ?? + "fullyQualifiedErrorId"; //Get ErrorCategory... ErrorCategory errorCategory = RemotingDecoder.GetPropertyValue(serializedErrorRecord, "errorCategory_Category"); @@ -1478,12 +1478,7 @@ namespace System.Management.Automation /// never null public ErrorCategoryInfo CategoryInfo { - get - { - if (null == _categoryInfo) - _categoryInfo = new ErrorCategoryInfo(this); - return _categoryInfo; - } + get { return _categoryInfo ?? (_categoryInfo = new ErrorCategoryInfo(this)); } } private ErrorCategoryInfo _categoryInfo; @@ -1669,7 +1664,7 @@ namespace System.Management.Automation internal static string NotNull(string s) { - return (null != s) ? s : ""; + return s ?? ""; } private string GetInvocationTypeName() diff --git a/src/System.Management.Automation/engine/EventManager.cs b/src/System.Management.Automation/engine/EventManager.cs index 2b1ba25b3..b5424fdc8 100644 --- a/src/System.Management.Automation/engine/EventManager.cs +++ b/src/System.Management.Automation/engine/EventManager.cs @@ -712,9 +712,7 @@ namespace System.Management.Automation } EventInfo eventInfo = null; - Type sourceType = source as Type; - if (sourceType == null) - sourceType = source.GetType(); + Type sourceType = source as Type ?? source.GetType(); //PowerShell does not support WinRT events. if (WinRTHelper.IsWinRTType(sourceType)) @@ -895,9 +893,7 @@ namespace System.Management.Automation EventInfo eventInfo = null; - Type sourceType = subscriber.SourceObject as Type; - if (sourceType == null) - sourceType = subscriber.SourceObject.GetType(); + Type sourceType = subscriber.SourceObject as Type ?? subscriber.SourceObject.GetType(); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase; eventInfo = sourceType.GetEvent(subscriber.EventName, bindingFlags); diff --git a/src/System.Management.Automation/engine/ExecutionContext.cs b/src/System.Management.Automation/engine/ExecutionContext.cs index d90c9731d..fd2b67026 100644 --- a/src/System.Management.Automation/engine/ExecutionContext.cs +++ b/src/System.Management.Automation/engine/ExecutionContext.cs @@ -563,13 +563,7 @@ namespace System.Management.Automation /// internal HelpSystem HelpSystem { - get - { - if (_helpSystem == null) - _helpSystem = new HelpSystem(this); - - return _helpSystem; - } + get { return _helpSystem ?? (_helpSystem = new HelpSystem(this)); } } private HelpSystem _helpSystem; @@ -651,14 +645,7 @@ namespace System.Management.Automation /// internal EngineIntrinsics EngineIntrinsics { - get - { - if (_engineIntrinsics == null) - { - _engineIntrinsics = new EngineIntrinsics(this); - } - return _engineIntrinsics; - } + get { return _engineIntrinsics ?? (_engineIntrinsics = new EngineIntrinsics(this)); } } private EngineIntrinsics _engineIntrinsics; @@ -1690,9 +1677,7 @@ namespace System.Management.Automation transactionManager = new PSTransactionManager(); _debugger = new ScriptDebugger(this); - EngineHostInterface = hostInterface as InternalHost; - if (EngineHostInterface == null) - EngineHostInterface = new InternalHost(hostInterface, this); + EngineHostInterface = hostInterface as InternalHost ?? new InternalHost(hostInterface, this); // Hook up the assembly cache AssemblyCache = new Dictionary(); diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 9bd4dd395..326a61550 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -1066,12 +1066,7 @@ namespace System.Management.Automation.Runspaces /// public Collection Attributes { - get - { - if (_attributes == null) - _attributes = new Collection(); - return _attributes; - } + get { return _attributes ?? (_attributes = new Collection()); } } private Collection _attributes; } @@ -1280,9 +1275,7 @@ namespace System.Management.Automation.Runspaces if (type != null) { - objType = type as Type; - if (objType == null) - objType = type.GetType(); + objType = type as Type ?? type.GetType(); } // Work backwards through the collection... diff --git a/src/System.Management.Automation/engine/InvocationInfo.cs b/src/System.Management.Automation/engine/InvocationInfo.cs index 68123e88f..e1f88da4c 100644 --- a/src/System.Management.Automation/engine/InvocationInfo.cs +++ b/src/System.Management.Automation/engine/InvocationInfo.cs @@ -206,11 +206,9 @@ namespace System.Management.Automation /// public Dictionary BoundParameters { - get - { - if (_boundParameters == null) - _boundParameters = new Dictionary(StringComparer.OrdinalIgnoreCase); - return _boundParameters; + get { + return _boundParameters ?? + (_boundParameters = new Dictionary(StringComparer.OrdinalIgnoreCase)); } internal set { _boundParameters = value; } } @@ -220,16 +218,8 @@ namespace System.Management.Automation /// public List UnboundArguments { - get - { - if (_unboundArguments == null) - _unboundArguments = new List(); - return _unboundArguments; - } - internal set - { - _unboundArguments = value; - } + get { return _unboundArguments ?? (_unboundArguments = new List()); } + internal set { _unboundArguments = value; } } /// diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 92150bf80..695341f6b 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -663,11 +663,7 @@ namespace System.Management.Automation string secondString; if (firstString != null) { - secondString = second as string; - if (secondString == null) - { - secondString = (string)LanguagePrimitives.ConvertTo(second, typeof(string), culture); - } + secondString = second as string ?? (string)LanguagePrimitives.ConvertTo(second, typeof(string), culture); return (culture.CompareInfo.Compare(firstString, secondString, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None) == 0); } @@ -2470,11 +2466,7 @@ namespace System.Management.Automation private static CultureInfo GetCultureFromFormatProvider(IFormatProvider formatProvider) { - CultureInfo returnValue = formatProvider as CultureInfo; - if (returnValue == null) - { - returnValue = CultureInfo.InvariantCulture; - } + CultureInfo returnValue = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture; return returnValue; } @@ -5126,11 +5118,8 @@ namespace System.Management.Automation castOperator = FindCastOperator("op_Explicit", toType, fromType, toType); if (castOperator == null) { - castOperator = FindCastOperator("op_Implicit", fromType, fromType, toType); - if (castOperator == null) - { - castOperator = FindCastOperator("op_Explicit", fromType, fromType, toType); - } + castOperator = FindCastOperator("op_Implicit", fromType, fromType, toType) ?? + FindCastOperator("op_Explicit", fromType, fromType, toType); } } diff --git a/src/System.Management.Automation/engine/ManagementObjectAdapter.cs b/src/System.Management.Automation/engine/ManagementObjectAdapter.cs index bee228932..7203d46ef 100644 --- a/src/System.Management.Automation/engine/ManagementObjectAdapter.cs +++ b/src/System.Management.Automation/engine/ManagementObjectAdapter.cs @@ -458,11 +458,7 @@ namespace System.Management.Automation // is fixed) typeTable = new CacheTable(); // Construct a ManagementClass object for this object to get the member metadata - ManagementClass mgmtClass = wmiObject as ManagementClass; - if (null == mgmtClass) - { - mgmtClass = CreateClassFrmObject(wmiObject); - } + ManagementClass mgmtClass = wmiObject as ManagementClass ?? CreateClassFrmObject(wmiObject); PopulateMethodTable(mgmtClass, typeTable, staticBinding); s_instanceMethodCacheTable[key] = typeTable; } diff --git a/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs index ebd7e5fa8..aabdb7209 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleCommand.cs @@ -164,10 +164,8 @@ namespace Microsoft.PowerShell.Commands // Export all functions and variables if no exports were specified... if (!localModule.SessionState.Internal.UseExportList) { - List cmdletPatterns = - BaseCmdletPatterns != null ? BaseCmdletPatterns : MatchAll; - List functionPatterns = - BaseFunctionPatterns != null ? BaseFunctionPatterns : MatchAll; + List cmdletPatterns = BaseCmdletPatterns ?? MatchAll; + List functionPatterns = BaseFunctionPatterns ?? MatchAll; ModuleIntrinsics.ExportModuleMembers(this, localModule.SessionState.Internal, diff --git a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs index ed087c47e..01d99d9b5 100644 --- a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs +++ b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs @@ -76,14 +76,7 @@ namespace System.Management.Automation } // Use the name of basename of the path as the module name if no module name is supplied. - if (name == null) - { - Name = ModuleIntrinsics.GetModuleName(Path); - } - else - { - Name = name; - } + Name = name ?? ModuleIntrinsics.GetModuleName(Path); } /// diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index 70cf2281d..be37fb8dc 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -985,11 +985,7 @@ namespace System.Management.Automation { using (PSTransactionManager.GetEngineProtectionScope()) { - if (_invokeCommand == null) - { - _invokeCommand = new CommandInvocationIntrinsics(Context, this); - } - return _invokeCommand; + return _invokeCommand ?? (_invokeCommand = new CommandInvocationIntrinsics(Context, this)); } } } //InvokeCommand diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index 81bd11041..0d3470d85 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -126,15 +126,7 @@ namespace System.Management.Automation /// The invocation object for this command. internal InvocationInfo MyInvocation { - get - { - if (_myInvocation == null) - { - _myInvocation = _thisCommand.MyInvocation; - } - - return _myInvocation; - } + get { return _myInvocation ?? (_myInvocation = _thisCommand.MyInvocation); } } /// @@ -934,14 +926,7 @@ namespace System.Management.Automation IList oldValue = null; oldValue = PSObject.Base(_state.PSVariable.GetValue(this.OutVariable)) as IList; - if (oldValue == null) - { - _outVarList = new ArrayList(); - } - else - { - _outVarList = oldValue; - } + _outVarList = oldValue ?? new ArrayList(); if (!(_thisCommand is PSScriptCmdlet)) { @@ -2186,12 +2171,7 @@ namespace System.Management.Automation /// internal Pipe InputPipe { - get - { - if (_inputPipe == null) - _inputPipe = new Pipe(); - return _inputPipe; - } + get { return _inputPipe ?? (_inputPipe = new Pipe()); } set { _inputPipe = value; } } @@ -2200,12 +2180,7 @@ namespace System.Management.Automation /// internal Pipe OutputPipe { - get - { - if (_outputPipe == null) - _outputPipe = new Pipe(); - return _outputPipe; - } + get { return _outputPipe ?? (_outputPipe = new Pipe()); } set { _outputPipe = value; } } @@ -2227,12 +2202,7 @@ namespace System.Management.Automation /// internal Pipe ErrorOutputPipe { - get - { - if (_errorOutputPipe == null) - _errorOutputPipe = new Pipe(); - return _errorOutputPipe; - } + get { return _errorOutputPipe ?? (_errorOutputPipe = new Pipe()); } set { _errorOutputPipe = value; } } diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index 17612778d..d44e3e7fd 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -883,7 +883,7 @@ namespace System.Management.Automation } catch (TargetInvocationException ex) { - Exception inner = (ex.InnerException == null) ? ex : ex.InnerException; + Exception inner = ex.InnerException ?? ex; throw new GetValueInvocationException("CatchFromCodePropertyGetTI", inner, ExtendedTypeSystem.ExceptionWhenGetting, @@ -917,7 +917,7 @@ namespace System.Management.Automation } catch (TargetInvocationException ex) { - Exception inner = (ex.InnerException == null) ? ex : ex.InnerException; + Exception inner = ex.InnerException ?? ex; throw new SetValueInvocationException("CatchFromCodePropertySetTI", inner, ExtendedTypeSystem.ExceptionWhenSetting, diff --git a/src/System.Management.Automation/engine/MshObject.cs b/src/System.Management.Automation/engine/MshObject.cs index e7d371f5e..2296470bb 100644 --- a/src/System.Management.Automation/engine/MshObject.cs +++ b/src/System.Management.Automation/engine/MshObject.cs @@ -1485,11 +1485,7 @@ namespace System.Management.Automation result = msjObjFormattable.ToString(format, formatProvider); } - if (result == null) - { - result = String.Empty; - } - return result; + return result ?? String.Empty; } catch (Exception e) { @@ -1912,7 +1908,7 @@ namespace System.Management.Automation { SerializationMethod result = TypeTable.defaultSerializationMethod; - TypeTable typeTable = backupTypeTable != null ? backupTypeTable : this.GetTypeTable(); + TypeTable typeTable = backupTypeTable ?? this.GetTypeTable(); if (null != typeTable) { PSMemberSet standardMemberSet = TypeTableGetMemberDelegate(this, @@ -1947,7 +1943,7 @@ namespace System.Management.Automation { PSMemberInfo result = null; - TypeTable typeTable = backupTypeTable != null ? backupTypeTable : this.GetTypeTable(); + TypeTable typeTable = backupTypeTable ?? this.GetTypeTable(); if (typeTable != null) { PSMemberSet standardMemberSet = TypeTableGetMemberDelegate( @@ -1963,12 +1959,7 @@ namespace System.Management.Automation } } - if (result == null) - { - result = this.InstanceMembers[TypeTable.PSStandardMembers] as PSMemberSet; - } - - return result; + return result ?? InstanceMembers[TypeTable.PSStandardMembers] as PSMemberSet; } /// @@ -2004,7 +1995,7 @@ namespace System.Management.Automation /// A collection with only the specific properties to serialize internal Collection GetSpecificPropertiesToSerialize(TypeTable backupTypeTable) { - TypeTable typeTable = backupTypeTable != null ? backupTypeTable : this.GetTypeTable(); + TypeTable typeTable = backupTypeTable ?? this.GetTypeTable(); if (null != typeTable) { Collection tmp = typeTable.GetSpecificProperties(this.InternalTypeNames); diff --git a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs index b6447ba52..81224e937 100644 --- a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs +++ b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs @@ -547,11 +547,8 @@ namespace System.Management.Automation return new TypeConverter(); } object baseObject = this.Instance.BaseObject; - TypeConverter retValue = LanguagePrimitives.GetConverter(baseObject.GetType(), null) as TypeConverter; - if (retValue == null) - { - retValue = TypeDescriptor.GetConverter(baseObject); - } + TypeConverter retValue = LanguagePrimitives.GetConverter(baseObject.GetType(), null) as TypeConverter ?? + TypeDescriptor.GetConverter(baseObject); return retValue; } diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 7f541e674..c8d3d9401 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -1410,11 +1410,8 @@ namespace System.Management.Automation //Get the encoding for writing to native command. Note we get the Encoding //from the current scope so a script or function can use a different encoding //than global value. - Encoding pipeEncoding = _command.Context.GetVariableValue(SpecialVariables.OutputEncodingVarPath) as System.Text.Encoding; - if (pipeEncoding == null) - { - pipeEncoding = Encoding.ASCII; - } + Encoding pipeEncoding = _command.Context.GetVariableValue(SpecialVariables.OutputEncodingVarPath) as System.Text.Encoding ?? + Encoding.ASCII; _streamWriter = new StreamWriter(process.StandardInput.BaseStream, pipeEncoding); diff --git a/src/System.Management.Automation/engine/PSMI/Serialization/InternalMISerializer.cs b/src/System.Management.Automation/engine/PSMI/Serialization/InternalMISerializer.cs index b475d66be..fee647292 100644 --- a/src/System.Management.Automation/engine/PSMI/Serialization/InternalMISerializer.cs +++ b/src/System.Management.Automation/engine/PSMI/Serialization/InternalMISerializer.cs @@ -48,13 +48,9 @@ namespace System.Management.Automation private Collection> _allPropertiesCollection; private Collection> AllPropertiesCollection { - get - { - if (_allPropertiesCollection == null) - { - _allPropertiesCollection = PSObject.GetPropertyCollection(PSMemberViewTypes.All, _typeTable); - } - return _allPropertiesCollection; + get { + return _allPropertiesCollection ?? + (_allPropertiesCollection = PSObject.GetPropertyCollection(PSMemberViewTypes.All, _typeTable)); } } diff --git a/src/System.Management.Automation/engine/ParameterBinderBase.cs b/src/System.Management.Automation/engine/ParameterBinderBase.cs index d105f02ce..b8d05c342 100644 --- a/src/System.Management.Automation/engine/ParameterBinderBase.cs +++ b/src/System.Management.Automation/engine/ParameterBinderBase.cs @@ -184,12 +184,7 @@ namespace System.Management.Automation { // Setter is needed to pass into RuntimeParameterBinder instances set { _commandLineParameters = value; } - get - { - if (_commandLineParameters == null) - _commandLineParameters = new CommandLineParameters(); - return _commandLineParameters; - } + get { return _commandLineParameters ?? (_commandLineParameters = new CommandLineParameters()); } } private CommandLineParameters _commandLineParameters; @@ -1309,7 +1304,7 @@ namespace System.Management.Automation { bindingTracer.TraceError( "ERROR: COERCE FAILED: arg [{0}] could not be converted to the parameter type [{1}]", - (result == null) ? "null" : result, + result ?? "null", toType); ParameterBindingException pbe = @@ -1323,7 +1318,7 @@ namespace System.Management.Automation argumentType, ParameterBinderStrings.CannotConvertArgument, "CannotConvertArgument", - (result == null) ? "null" : result, + result ?? "null", notSupported.Message); throw pbe; diff --git a/src/System.Management.Automation/engine/PathInterfaces.cs b/src/System.Management.Automation/engine/PathInterfaces.cs index c41509649..86136db54 100644 --- a/src/System.Management.Automation/engine/PathInterfaces.cs +++ b/src/System.Management.Automation/engine/PathInterfaces.cs @@ -1601,11 +1601,7 @@ namespace System.Management.Automation _sessionState != null, "The only constructor for this class should always set the sessionState field"); - if (_pathResolver == null) - { - _pathResolver = _sessionState.ExecutionContext.LocationGlobber; - } - return _pathResolver; + return _pathResolver ?? (_pathResolver = _sessionState.ExecutionContext.LocationGlobber); } // get } // PathResolver diff --git a/src/System.Management.Automation/engine/ProxyCommand.cs b/src/System.Management.Automation/engine/ProxyCommand.cs index db8999ff4..843e1d4b0 100644 --- a/src/System.Management.Automation/engine/ProxyCommand.cs +++ b/src/System.Management.Automation/engine/ProxyCommand.cs @@ -263,12 +263,7 @@ namespace System.Management.Automation { text = GetProperty(psobj, "Text"); } - if (text == null) - { - text = obj.ToString(); - } - - return text; + return text ?? obj.ToString(); } private static void AppendContent(StringBuilder sb, string section, object obj) @@ -389,11 +384,7 @@ namespace System.Management.Automation sb.Append("\n\n"); foreach (PSObject obj in description) { - string text = GetProperty(obj, "Text"); - if (text == null) - { - text = obj.ToString(); - } + string text = GetProperty(obj, "Text") ?? obj.ToString(); if (!string.IsNullOrEmpty(text)) { sb.Append(text); diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index e7cbca866..9b8fd3bdb 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -145,14 +145,7 @@ namespace System.Management.Automation /// internal LocationGlobber Globber { - get - { - if (_globberPrivate == null) - { - _globberPrivate = ExecutionContext.LocationGlobber; - } - return _globberPrivate; - } + get { return _globberPrivate ?? (_globberPrivate = ExecutionContext.LocationGlobber); } } private LocationGlobber _globberPrivate; @@ -166,18 +159,8 @@ namespace System.Management.Automation /// internal SessionState PublicSessionState { - get - { - if (_publicSessionState == null) - { - _publicSessionState = new SessionState(this); - } - return _publicSessionState; - } - set - { - _publicSessionState = value; - } + get { return _publicSessionState ?? (_publicSessionState = new SessionState(this)); } + set { _publicSessionState = value; } } private SessionState _publicSessionState; @@ -186,13 +169,8 @@ namespace System.Management.Automation /// internal ProviderIntrinsics InvokeProvider { - get - { - if (_invokeProvider == null) - _invokeProvider = new ProviderIntrinsics(this); - return _invokeProvider; - } // get - } // InvokeProvider + get { return _invokeProvider ?? (_invokeProvider = new ProviderIntrinsics(this)); } // get + } private ProviderIntrinsics _invokeProvider; /// diff --git a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs index 6e419a8ff..b458419dc 100644 --- a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs @@ -37,11 +37,8 @@ namespace System.Management.Automation { var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null); - var workflowInfo = entry.WorkflowInfo; - if (workflowInfo == null) - { - workflowInfo = converterInstance.CompileWorkflow(entry.Name, entry.Definition, initialSessionState); - } + var workflowInfo = entry.WorkflowInfo ?? + converterInstance.CompileWorkflow(entry.Name, entry.Definition, initialSessionState); WorkflowInfo wf = new WorkflowInfo(workflowInfo); diff --git a/src/System.Management.Automation/engine/SessionStatePublic.cs b/src/System.Management.Automation/engine/SessionStatePublic.cs index 50849bda2..f9e3b55f8 100644 --- a/src/System.Management.Automation/engine/SessionStatePublic.cs +++ b/src/System.Management.Automation/engine/SessionStatePublic.cs @@ -100,74 +100,40 @@ namespace System.Management.Automation /// public DriveManagementIntrinsics Drive { - get - { - if (_drive == null) - { - _drive = new DriveManagementIntrinsics(_sessionState); - } - return _drive; - } - } // Drive + get { return _drive ?? (_drive = new DriveManagementIntrinsics(_sessionState)); } + } /// /// Gets the APIs to access providers /// public CmdletProviderManagementIntrinsics Provider { - get - { - if (_provider == null) - { - _provider = new CmdletProviderManagementIntrinsics(_sessionState); - } - return _provider; - } // get - } // Provider + get { return _provider ?? (_provider = new CmdletProviderManagementIntrinsics(_sessionState)); } // get + } /// /// Gets the APIs to access paths and location /// public PathIntrinsics Path { - get - { - if (_path == null) - { - _path = new PathIntrinsics(_sessionState); - } - return _path; - } // get - } // Path + get { return _path ?? (_path = new PathIntrinsics(_sessionState)); } + } /// /// Gets the APIs to access variables in session state. /// public PSVariableIntrinsics PSVariable { - get - { - if (_variable == null) - { - _variable = new PSVariableIntrinsics(_sessionState); - } - return _variable; - } // get - } // PSVariable + get { return _variable ?? (_variable = new PSVariableIntrinsics(_sessionState)); } // get + } /// /// Get/set constraints for this execution environemnt /// public PSLanguageMode LanguageMode { - get - { - return _sessionState.LanguageMode; - } - set - { - _sessionState.LanguageMode = value; - } + get { return _sessionState.LanguageMode; } + set { _sessionState.LanguageMode = value; } } /// @@ -175,10 +141,7 @@ namespace System.Management.Automation /// public bool UseFullLanguageModeInDebugger { - get - { - return _sessionState.UseFullLanguageModeInDebugger; - } + get { return _sessionState.UseFullLanguageModeInDebugger; } } /// diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index d7b9f063d..ae46fd292 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -2045,14 +2045,7 @@ namespace System.Management.Automation // performance degradation, so we use lazy initialization for all of them. private Dictionary GetDrives() { - if (_drives == null) - { - // Create the drives collection with the default parameters - _drives = - new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - return _drives; + return _drives ?? (_drives = new Dictionary(StringComparer.OrdinalIgnoreCase)); } private Dictionary _drives; @@ -2064,15 +2057,10 @@ namespace System.Management.Automation // performance degradation, so we use lazy initialization for all of them. private Dictionary GetAutomountedDrives() { - if (_automountedDrives == null) - { - // Create the drives collection with the default parameters - _automountedDrives = - new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - return _automountedDrives; + return _automountedDrives ?? + (_automountedDrives = new Dictionary(StringComparer.OrdinalIgnoreCase)); } + private Dictionary _automountedDrives; private Dictionary _variables; diff --git a/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs b/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs index 9d36602bf..cae6342fc 100644 --- a/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs +++ b/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs @@ -93,12 +93,7 @@ namespace System.Management.Automation context.ThrowFirstErrorOrDoNothing(); - Collection contextResults = context.GetAccumulatedObjects(); - - if (contextResults == null) - { - contextResults = new Collection(); - } + Collection contextResults = context.GetAccumulatedObjects() ?? new Collection(); return contextResults; } // GetSecurityDescriptor @@ -245,14 +240,8 @@ namespace System.Management.Automation context.ThrowFirstErrorOrDoNothing(); - Collection contextResults = context.GetAccumulatedObjects(); - // Return an empty array instead of null - - if (contextResults == null) - { - contextResults = new Collection(); - } + Collection contextResults = context.GetAccumulatedObjects() ?? new Collection(); return contextResults; } // SetSecurityDescriptor diff --git a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs index cde53c64d..191c38008 100644 --- a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs @@ -185,13 +185,9 @@ namespace System.Management.Automation /// internal object GetVariableValue(string name, object defaultValue) { - object returnObject = GetVariableValue(name); - if (returnObject == null) - { - returnObject = defaultValue; - } + object returnObject = GetVariableValue(name) ?? defaultValue; return returnObject; - } // GetVariableValue + } /// /// Looks up the specified variable and returns the context under which @@ -1473,11 +1469,7 @@ namespace System.Management.Automation IContentWriter writer = writers[0]; - IList content = newValue as IList; - if (content == null) - { - content = new object[] { newValue }; - } + IList content = newValue as IList ?? new object[] { newValue }; try { diff --git a/src/System.Management.Automation/engine/ShellVariable.cs b/src/System.Management.Automation/engine/ShellVariable.cs index ac911ca09..360d43dfe 100644 --- a/src/System.Management.Automation/engine/ShellVariable.cs +++ b/src/System.Management.Automation/engine/ShellVariable.cs @@ -416,14 +416,7 @@ namespace System.Management.Automation /// public Collection Attributes { - get - { - if (_attributes == null) - { - _attributes = new PSVariableAttributeCollection(this); - } - return _attributes; - } + get { return _attributes ?? (_attributes = new PSVariableAttributeCollection(this)); } } private PSVariableAttributeCollection _attributes; @@ -886,20 +879,8 @@ namespace System.Management.Automation /// public override string Description { - get - { - if (_description == null) - { - _description = - SessionStateStrings.DollarNullDescription; - } - return _description; - } - - set - { - // Do nothing - } + get { return _description ?? (_description = SessionStateStrings.DollarNullDescription); } + set { /* Do nothing */ } } private string _description; @@ -908,15 +889,8 @@ namespace System.Management.Automation /// public override ScopedItemOptions Options { - get - { - return ScopedItemOptions.None; - } - - set - { - // Do nothing - } + get { return ScopedItemOptions.None; } + set { /* Do nothing */ } } } diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs index 34ce251c3..27992a269 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs @@ -1610,11 +1610,7 @@ namespace System.Management.Automation.Runspaces /// internal override SessionStateProxy GetSessionStateProxy() { - if (_sessionStateProxy == null) - { - _sessionStateProxy = new SessionStateProxy(this); - } - return _sessionStateProxy; + return _sessionStateProxy ?? (_sessionStateProxy = new SessionStateProxy(this)); } #endregion session state proxy diff --git a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs index c062c0f0d..978a3e10d 100644 --- a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs +++ b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs @@ -339,18 +339,9 @@ namespace System.Management.Automation.Host Collection Attributes { - get - { - if (_metadata == null) - { - _metadata = new Collection(); - } - return _metadata; - } + get { return _metadata ?? (_metadata = new Collection()); } } - - /// /// /// For use by remoting serialization. diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHost.cs b/src/System.Management.Automation/engine/hostifaces/InternalHost.cs index d4146847f..705f87b7c 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHost.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHost.cs @@ -195,12 +195,7 @@ namespace System.Management.Automation.Internal.Host { get { - CultureInfo ci = _externalHostRef.Value.CurrentCulture; - - if (ci == null) - { - ci = CultureInfo.InvariantCulture; - } + CultureInfo ci = _externalHostRef.Value.CurrentCulture ?? CultureInfo.InvariantCulture; return ci; } diff --git a/src/System.Management.Automation/engine/hostifaces/ListModifier.cs b/src/System.Management.Automation/engine/hostifaces/ListModifier.cs index 2f2eb27ee..5d2953734 100644 --- a/src/System.Management.Automation/engine/hostifaces/ListModifier.cs +++ b/src/System.Management.Automation/engine/hostifaces/ListModifier.cs @@ -40,8 +40,8 @@ namespace System.Management.Automation /// The items to add public PSListModifier(Collection removeItems, Collection addItems) { - _itemsToAdd = (addItems != null) ? addItems : new Collection(); - _itemsToRemove = (removeItems != null) ? removeItems : new Collection(); + _itemsToAdd = addItems ?? new Collection(); + _itemsToRemove = removeItems ?? new Collection(); _replacementItems = new Collection(); } diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index b333896c2..bd74a8a1c 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -622,7 +622,7 @@ namespace System.Management.Automation private PowerShell(PSCommand command, Collection extraCommands, object rsConnection) { Dbg.Assert(command != null, "command must not be null"); - ExtraCommands = (extraCommands == null) ? new Collection() : extraCommands; + ExtraCommands = extraCommands ?? new Collection(); RunningExtraCommands = false; _psCommand = command; _psCommand.Owner = this; @@ -3207,12 +3207,7 @@ namespace System.Management.Automation try { - objs = EndInvoke(result); - - if (objs == null) - { - objs = _batchAsyncResult.Output; - } + objs = EndInvoke(result) ?? _batchAsyncResult.Output; DoRemainingBatchCommands(objs); } diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs index 3cfa58a58..fb90be824 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs @@ -77,11 +77,6 @@ namespace System.Management.Automation.Runspaces // PSConsoleFile parameters before parsing other parameters. // The other parameters get parsed in the managed layer. Version tempVersion = powerShellVersion ?? PSVersionInfo.PSVersion; - // tempVersion can never get to null..but FxCop thinks otherwise. - if (null == tempVersion) - { - tempVersion = PSVersionInfo.PSVersion; - } processArguments = string.Format(CultureInfo.InvariantCulture, "-Version {0}", new Version(tempVersion.Major, tempVersion.Minor)); diff --git a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs index bc9ea4266..9d0e5fa32 100644 --- a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs +++ b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs @@ -68,14 +68,7 @@ namespace System.Management.Automation.Interpreter public override Instruction[] Cache { - get - { - if (s_cache == null) - { - s_cache = new Instruction[CacheSize]; - } - return s_cache; - } + get { return s_cache ?? (s_cache = new Instruction[CacheSize]); } } internal BranchFalseInstruction() @@ -103,14 +96,7 @@ namespace System.Management.Automation.Interpreter public override Instruction[] Cache { - get - { - if (s_cache == null) - { - s_cache = new Instruction[CacheSize]; - } - return s_cache; - } + get { return s_cache ?? (s_cache = new Instruction[CacheSize]); } } internal BranchTrueInstruction() @@ -138,14 +124,7 @@ namespace System.Management.Automation.Interpreter public override Instruction[] Cache { - get - { - if (s_cache == null) - { - s_cache = new Instruction[CacheSize]; - } - return s_cache; - } + get { return s_cache ?? (s_cache = new Instruction[CacheSize]); } } internal CoalescingBranchInstruction() diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index 6f6d2850a..5860b89aa 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -521,12 +521,7 @@ namespace System.Management.Automation // more details. private static IEnumerable enumerateContent(ExecutionContext context, IScriptExtent errorPosition, SplitImplOptions implOptions, object tuple) { - IEnumerator enumerator = LanguagePrimitives.GetEnumerator(tuple); - if (enumerator == null) - { - // Single value. Treat as a 1-tuple. - enumerator = new object[] { tuple }.GetEnumerator(); - } + IEnumerator enumerator = LanguagePrimitives.GetEnumerator(tuple) ?? new object[] { tuple }.GetEnumerator(); while (ParserOps.MoveNext(context, errorPosition, enumerator)) { @@ -865,7 +860,7 @@ namespace System.Management.Automation IEnumerator list = LanguagePrimitives.GetEnumerator(lval); if (list == null) { - string lvalString = ((lval == null) ? String.Empty : lval).ToString(); + string lvalString = lval?.ToString() ?? String.Empty; // Find a single match in the string. return rr.Replace(lvalString, replacement); diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index b17f6b8f3..61c100608 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -394,12 +394,7 @@ namespace System.Management.Automation.Language } } - if (baseClass == null) - { - baseClass = typeof(object); - } - - return baseClass; + return baseClass ?? typeof(object); } public void DefineMembers() diff --git a/src/System.Management.Automation/engine/remoting/client/Job.cs b/src/System.Management.Automation/engine/remoting/client/Job.cs index d7e28f63a..c3d00a3dc 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job.cs @@ -672,7 +672,7 @@ namespace System.Management.Automation get { return _jobTypeName; } protected internal set { - _jobTypeName = (value != null) ? value : this.GetType().ToString(); + _jobTypeName = value ?? this.GetType().ToString(); } } diff --git a/src/System.Management.Automation/engine/remoting/client/PowerShellStreams.cs b/src/System.Management.Automation/engine/remoting/client/PowerShellStreams.cs index 11c304f5b..51f0753c2 100644 --- a/src/System.Management.Automation/engine/remoting/client/PowerShellStreams.cs +++ b/src/System.Management.Automation/engine/remoting/client/PowerShellStreams.cs @@ -82,14 +82,7 @@ namespace System.Management.Automation public PowerShellStreams(PSDataCollection pipelineInput) { // Populate the input collection if there is any... - if (pipelineInput == null) - { - _inputStream = new PSDataCollection(); - } - else - { - _inputStream = pipelineInput; - } + _inputStream = pipelineInput ?? new PSDataCollection(); _inputStream.Complete(); diff --git a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs index 160a0fa2e..aaf288b92 100644 --- a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs @@ -228,18 +228,7 @@ namespace System.Management.Automation.Runspaces.Internal internal string Name { get { return _friendlyName; } - - set - { - if (value == null) - { - _friendlyName = string.Empty; - } - else - { - _friendlyName = value; - } - } + set { _friendlyName = value ?? string.Empty; } } /// diff --git a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs index 8754fd9ee..5a35801ce 100644 --- a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs +++ b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs @@ -1220,11 +1220,9 @@ namespace System.Management.Automation /// internal override SessionStateProxy GetSessionStateProxy() { - if (_sessionStateProxy == null) - _sessionStateProxy = new RemoteSessionStateProxy(this); - - return _sessionStateProxy; + return _sessionStateProxy ?? (_sessionStateProxy = new RemoteSessionStateProxy(this)); } + private RemoteSessionStateProxy _sessionStateProxy = null; #endregion SessionState Proxy diff --git a/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs b/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs index f19969557..92ec53c56 100644 --- a/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs +++ b/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs @@ -1392,7 +1392,7 @@ namespace Microsoft.PowerShell.Commands catch (System.Xml.XmlException) { } - return (rtnMsg != null) ? rtnMsg : e.Message; + return rtnMsg ?? e.Message; } /// diff --git a/src/System.Management.Automation/engine/remoting/commands/DisconnectPSSession.cs b/src/System.Management.Automation/engine/remoting/commands/DisconnectPSSession.cs index 62135c418..a513c6352 100644 --- a/src/System.Management.Automation/engine/remoting/commands/DisconnectPSSession.cs +++ b/src/System.Management.Automation/engine/remoting/commands/DisconnectPSSession.cs @@ -108,11 +108,7 @@ namespace Microsoft.PowerShell.Commands { // no need to lock as the cmdlet parameters will not be assigned // from multiple threads. - if (null == _sessionOption) - { - _sessionOption = new PSSessionOption(); - } - return _sessionOption; + return _sessionOption ?? (_sessionOption = new PSSessionOption()); } } private PSSessionOption _sessionOption; diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index f5f2c177c..969cef80f 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -1585,11 +1585,8 @@ namespace System.Management.Automation { Dbg.Assert(exception != null, "Caller should validate the data"); - ErrorRecord er = GetErrorRecordFromException(exception); - if (er == null) - { - er = new ErrorRecord(exception, errorId, category, null); - } + ErrorRecord er = GetErrorRecordFromException(exception) ?? + new ErrorRecord(exception, errorId, category, null); return new PSNoteProperty(RemoteDataNameStrings.ExceptionAsErrorRecord, er); } diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index 28c7edef8..14097f465 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -1874,26 +1874,19 @@ namespace System.Management.Automation private Collection> _extendedMembersCollection; private Collection> ExtendedMembersCollection { - get - { - if (_extendedMembersCollection == null) - { - _extendedMembersCollection = PSObject.GetMemberCollection(PSMemberViewTypes.Extended, _typeTable); - } - return _extendedMembersCollection; + get { + return _extendedMembersCollection ?? + (_extendedMembersCollection = + PSObject.GetMemberCollection(PSMemberViewTypes.Extended, _typeTable)); } } private Collection> _allPropertiesCollection; private Collection> AllPropertiesCollection { - get - { - if (_allPropertiesCollection == null) - { - _allPropertiesCollection = PSObject.GetPropertyCollection(PSMemberViewTypes.All, _typeTable); - } - return _allPropertiesCollection; + get { + return _allPropertiesCollection ?? + (_allPropertiesCollection = PSObject.GetPropertyCollection(PSMemberViewTypes.All, _typeTable)); } } @@ -4782,12 +4775,7 @@ namespace System.Management.Automation } } - if (ex == null) - { - ex = new XmlException(message, innerException); - } - - return ex; + return ex ?? new XmlException(message, innerException); } private string ReadNameAttribute() diff --git a/src/System.Management.Automation/help/UpdatableHelpCommandBase.cs b/src/System.Management.Automation/help/UpdatableHelpCommandBase.cs index 91865ea24..e31a6cb85 100644 --- a/src/System.Management.Automation/help/UpdatableHelpCommandBase.cs +++ b/src/System.Management.Automation/help/UpdatableHelpCommandBase.cs @@ -487,18 +487,9 @@ namespace Microsoft.PowerShell.Commands return; } - IEnumerable cultures; - - if (_language == null) - { - // Win8: 572882 When the system locale is English and the UI is JPN, - // running "update-help" still downs English help content. - cultures = _helpSystem.GetCurrentUICulture(); - } - else - { - cultures = _language; - } + // Win8: 572882 When the system locale is English and the UI is JPN, + // running "update-help" still downs English help content. + var cultures = _language ?? _helpSystem.GetCurrentUICulture(); foreach (string culture in cultures) { diff --git a/src/System.Management.Automation/minishell/api/RunspaceConfiguration.cs b/src/System.Management.Automation/minishell/api/RunspaceConfiguration.cs index 93417aadc..a135b08da 100644 --- a/src/System.Management.Automation/minishell/api/RunspaceConfiguration.cs +++ b/src/System.Management.Automation/minishell/api/RunspaceConfiguration.cs @@ -360,14 +360,8 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Cmdlets { - get - { - if (_cmdlets == null) - { - _cmdlets = new RunspaceConfigurationEntryCollection(); - } - - return _cmdlets; + get { + return _cmdlets ?? (_cmdlets = new RunspaceConfigurationEntryCollection()); } } @@ -381,14 +375,9 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Providers { - get - { - if (_providers == null) - { - _providers = new RunspaceConfigurationEntryCollection(); - } - - return _providers; + get { + return _providers ?? + (_providers = new RunspaceConfigurationEntryCollection()); } } @@ -412,12 +401,7 @@ namespace System.Management.Automation.Runspaces /// internal TypeTable TypeTable { - get - { - if (_typeTable == null) - _typeTable = new TypeTable(); - return _typeTable; - } + get { return _typeTable ?? (_typeTable = new TypeTable()); } } private TypeTable _typeTable; @@ -432,15 +416,7 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Types { - get - { - if (_types == null) - { - _types = new RunspaceConfigurationEntryCollection(); - } - - return _types; - } + get { return _types ?? (_types = new RunspaceConfigurationEntryCollection()); } } private RunspaceConfigurationEntryCollection _formats; @@ -454,14 +430,8 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Formats { - get - { - if (_formats == null) - { - _formats = new RunspaceConfigurationEntryCollection(); - } - - return _formats; + get { + return _formats ?? (_formats = new RunspaceConfigurationEntryCollection()); } } @@ -482,14 +452,8 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Scripts { - get - { - if (_scripts == null) - { - _scripts = new RunspaceConfigurationEntryCollection(); - } - - return _scripts; + get { + return _scripts ?? (_scripts = new RunspaceConfigurationEntryCollection()); } } @@ -508,14 +472,9 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection InitializationScripts { - get - { - if (_initializationScripts == null) - { - _initializationScripts = new RunspaceConfigurationEntryCollection(); - } - - return _initializationScripts; + get { + return _initializationScripts ?? + (_initializationScripts = new RunspaceConfigurationEntryCollection()); } } @@ -534,14 +493,9 @@ namespace System.Management.Automation.Runspaces /// public virtual RunspaceConfigurationEntryCollection Assemblies { - get - { - if (_assemblies == null) - { - _assemblies = new RunspaceConfigurationEntryCollection(); - } - - return _assemblies; + get { + return _assemblies ?? + (_assemblies = new RunspaceConfigurationEntryCollection()); } } @@ -560,14 +514,9 @@ namespace System.Management.Automation.Runspaces /// public virtual AuthorizationManager AuthorizationManager { - get - { - if (_authorizationManager == null) - { - _authorizationManager = new Microsoft.PowerShell.PSAuthorizationManager(this.ShellId); - } - - return _authorizationManager; + get { + return _authorizationManager ?? + (_authorizationManager = new Microsoft.PowerShell.PSAuthorizationManager(this.ShellId)); } } diff --git a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs index 312b53ce0..8c750cdfc 100644 --- a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs +++ b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs @@ -1224,11 +1224,7 @@ namespace Microsoft.PowerShell.Commands if (getItemValueResult != null) { - result = getItemValueResult as IList; - if (result == null) - { - result = new object[] { getItemValueResult }; - } + result = getItemValueResult as IList ?? new object[] { getItemValueResult }; } _contentRead = true; } diff --git a/src/System.Management.Automation/security/SecureStringHelper.cs b/src/System.Management.Automation/security/SecureStringHelper.cs index bef93e954..c5e822a9c 100644 --- a/src/System.Management.Automation/security/SecureStringHelper.cs +++ b/src/System.Management.Automation/security/SecureStringHelper.cs @@ -387,16 +387,7 @@ namespace Microsoft.PowerShell Aes aes = Aes.Create(); encryptedData = ByteArrayFromString(input); - ICryptoTransform decryptor = null; - - if (IV != null) - { - decryptor = aes.CreateDecryptor(key, IV); - } - else - { - decryptor = aes.CreateDecryptor(key, aes.IV); - } + var decryptor = aes.CreateDecryptor(key, IV ?? aes.IV); MemoryStream ms = new MemoryStream(encryptedData); diff --git a/src/System.Management.Automation/singleshell/Commands/MshSnapinCommands.cs b/src/System.Management.Automation/singleshell/Commands/MshSnapinCommands.cs index 0716b45ad..3ae3df40b 100644 --- a/src/System.Management.Automation/singleshell/Commands/MshSnapinCommands.cs +++ b/src/System.Management.Automation/singleshell/Commands/MshSnapinCommands.cs @@ -248,13 +248,8 @@ namespace Microsoft.PowerShell.Commands /// internal RegistryStringResourceIndirect ResourceReader { - get - { - if (_resourceReader == null) - { - _resourceReader = RegistryStringResourceIndirect.GetResourceIndirectReader(); - } - return _resourceReader; + get { + return _resourceReader ?? (_resourceReader = RegistryStringResourceIndirect.GetResourceIndirectReader()); } } private RegistryStringResourceIndirect _resourceReader; diff --git a/src/System.Management.Automation/singleshell/config/RunspaceConfigForSingleShell.cs b/src/System.Management.Automation/singleshell/config/RunspaceConfigForSingleShell.cs index bdeee7000..eac791aa9 100644 --- a/src/System.Management.Automation/singleshell/config/RunspaceConfigForSingleShell.cs +++ b/src/System.Management.Automation/singleshell/config/RunspaceConfigForSingleShell.cs @@ -719,15 +719,7 @@ namespace System.Management.Automation.Runspaces /// public override RunspaceConfigurationEntryCollection Types { - get - { - if (_types == null) - { - _types = new RunspaceConfigurationEntryCollection(); - } - - return _types; - } + get { return _types ?? (_types = new RunspaceConfigurationEntryCollection()); } } private RunspaceConfigurationEntryCollection _formats; @@ -737,14 +729,8 @@ namespace System.Management.Automation.Runspaces /// public override RunspaceConfigurationEntryCollection Formats { - get - { - if (_formats == null) - { - _formats = new RunspaceConfigurationEntryCollection(); - } - - return _formats; + get { + return _formats ?? (_formats = new RunspaceConfigurationEntryCollection()); } } @@ -755,14 +741,9 @@ namespace System.Management.Automation.Runspaces /// public override RunspaceConfigurationEntryCollection InitializationScripts { - get - { - if (_initializationScripts == null) - { - _initializationScripts = new RunspaceConfigurationEntryCollection(); - } - - return _initializationScripts; + get { + return _initializationScripts ?? + (_initializationScripts = new RunspaceConfigurationEntryCollection()); } } diff --git a/src/System.Management.Automation/singleshell/installer/CustomMshSnapin.cs b/src/System.Management.Automation/singleshell/installer/CustomMshSnapin.cs index e6bd6f696..0ad985487 100644 --- a/src/System.Management.Automation/singleshell/installer/CustomMshSnapin.cs +++ b/src/System.Management.Automation/singleshell/installer/CustomMshSnapin.cs @@ -56,15 +56,7 @@ namespace System.Management.Automation /// public virtual Collection Cmdlets { - get - { - if (_cmdlets == null) - { - _cmdlets = new Collection(); - } - - return _cmdlets; - } + get { return _cmdlets ?? (_cmdlets = new Collection()); } } private Collection _providers; @@ -77,15 +69,7 @@ namespace System.Management.Automation /// public virtual Collection Providers { - get - { - if (_providers == null) - { - _providers = new Collection(); - } - - return _providers; - } + get { return _providers ?? (_providers = new Collection()); } } private Collection _types; @@ -98,15 +82,7 @@ namespace System.Management.Automation /// public virtual Collection Types { - get - { - if (_types == null) - { - _types = new Collection(); - } - - return _types; - } + get { return _types ?? (_types = new Collection()); } } private Collection _formats; @@ -119,15 +95,7 @@ namespace System.Management.Automation /// public virtual Collection Formats { - get - { - if (_formats == null) - { - _formats = new Collection(); - } - - return _formats; - } + get { return _formats ?? (_formats = new Collection()); } } private Dictionary _regValues = null; diff --git a/src/System.Management.Automation/singleshell/installer/MshSnapinInstaller.cs b/src/System.Management.Automation/singleshell/installer/MshSnapinInstaller.cs index 259c8017e..df50f4f53 100644 --- a/src/System.Management.Automation/singleshell/installer/MshSnapinInstaller.cs +++ b/src/System.Management.Automation/singleshell/installer/MshSnapinInstaller.cs @@ -105,13 +105,7 @@ namespace System.Management.Automation /// private string PSVersion { - get - { - if (_psVersion == null) - _psVersion = PSVersionInfo.FeatureVersionString; - - return _psVersion; - } + get { return _psVersion ?? (_psVersion = PSVersionInfo.FeatureVersionString); } } /// diff --git a/src/System.Management.Automation/utils/ExecutionExceptions.cs b/src/System.Management.Automation/utils/ExecutionExceptions.cs index 8298a0ac6..461da097b 100644 --- a/src/System.Management.Automation/utils/ExecutionExceptions.cs +++ b/src/System.Management.Automation/utils/ExecutionExceptions.cs @@ -709,14 +709,8 @@ namespace System.Management.Automation /// public override string Message { - get - { - if (null == _message) - { - _message = (null != _wrapperException) ? _wrapperException.Message : String.Empty; - } - - return _message; + get { + return _message ?? (_message = (null != _wrapperException) ? _wrapperException.Message : String.Empty); } } diff --git a/src/System.Management.Automation/utils/ObjectStream.cs b/src/System.Management.Automation/utils/ObjectStream.cs index f53b1719b..22e41b092 100644 --- a/src/System.Management.Automation/utils/ObjectStream.cs +++ b/src/System.Management.Automation/utils/ObjectStream.cs @@ -1253,12 +1253,7 @@ namespace System.Management.Automation.Internal RaiseEvents(); } } - if (results == null) - { - results = new Collection(); - } - - return results; + return results ?? new Collection(); } // NonBlockingRead /// diff --git a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs index 6dca02238..92458585a 100644 --- a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs +++ b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs @@ -424,14 +424,7 @@ namespace System.Management.Automation /// public override string Message { - get - { - if (_message == null) - { - _message = BuildMessage(); - } - return _message; - } + get { return _message ?? (_message = BuildMessage()); } } private string _message; diff --git a/src/System.Management.Automation/utils/StructuredTraceSource.cs b/src/System.Management.Automation/utils/StructuredTraceSource.cs index 10c4d8ade..59d6786d2 100644 --- a/src/System.Management.Automation/utils/StructuredTraceSource.cs +++ b/src/System.Management.Automation/utils/StructuredTraceSource.cs @@ -1455,14 +1455,7 @@ namespace System.Management.Automation /// internal TraceSource TraceSource { - get - { - if (_traceSource == null) - { - _traceSource = new MonadTraceSource(_name); - } - return _traceSource; - } + get { return _traceSource ?? (_traceSource = new MonadTraceSource(_name)); } } private TraceSource _traceSource; diff --git a/src/System.Management.Automation/utils/WindowsErrorReporting.cs b/src/System.Management.Automation/utils/WindowsErrorReporting.cs index fef922a0c..3c0bff6e9 100644 --- a/src/System.Management.Automation/utils/WindowsErrorReporting.cs +++ b/src/System.Management.Automation/utils/WindowsErrorReporting.cs @@ -668,11 +668,7 @@ namespace System.Management.Automation private static string GetThreadName() { - string threadName = System.Threading.Thread.CurrentThread.Name; - if (threadName == null) - { - threadName = string.Empty; - } + string threadName = System.Threading.Thread.CurrentThread.Name ?? string.Empty; return threadName; } diff --git a/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs b/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs index b1cd35571..ef4f20c32 100644 --- a/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs +++ b/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs @@ -194,14 +194,7 @@ namespace System.Management.Automation.PerformanceData /// public CounterSetInstanceBase CounterSetInstance { - get - { - if (this._counterSetInstanceBase == null) - { - this._counterSetInstanceBase = this.CreateCounterSetInstance(); - } - return this._counterSetInstanceBase; - } + get { return _counterSetInstanceBase ?? (_counterSetInstanceBase = CreateCounterSetInstance()); } } #endregion diff --git a/src/System.Management.Automation/utils/perfCounters/PSPerfCountersMgr.cs b/src/System.Management.Automation/utils/perfCounters/PSPerfCountersMgr.cs index 08454da68..4924dd3f2 100644 --- a/src/System.Management.Automation/utils/perfCounters/PSPerfCountersMgr.cs +++ b/src/System.Management.Automation/utils/perfCounters/PSPerfCountersMgr.cs @@ -57,14 +57,7 @@ namespace System.Management.Automation.PerformanceData /// public static PSPerfCountersMgr Instance { - get - { - if (s_PSPerfCountersMgrInstance == null) - { - s_PSPerfCountersMgrInstance = new PSPerfCountersMgr(); - } - return s_PSPerfCountersMgrInstance; - } + get { return s_PSPerfCountersMgrInstance ?? (s_PSPerfCountersMgrInstance = new PSPerfCountersMgr()); } } ///