diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/TerminatingErrorTracker.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/TerminatingErrorTracker.cs index 12e484ef0..81f1e9ca7 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/TerminatingErrorTracker.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/TerminatingErrorTracker.cs @@ -154,7 +154,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim else { sessionWasAlreadyTerminated = false; - return sessionException; + return null; } } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs index 4cfe26961..cb1670ef6 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs @@ -167,7 +167,6 @@ namespace Microsoft.PowerShell.Commands /// internal ManagementObjectSearcher GetObjectList(ManagementScope scope) { - ManagementObjectSearcher searcher = null; StringBuilder queryStringBuilder = new StringBuilder(); if (string.IsNullOrEmpty(this.Class)) { @@ -177,7 +176,7 @@ namespace Microsoft.PowerShell.Commands { string filterClass = GetFilterClassName(); if (filterClass == null) - return searcher; + return null; queryStringBuilder.Append("select * from meta_class where __class like '"); queryStringBuilder.Append(filterClass); queryStringBuilder.Append("'"); @@ -187,7 +186,7 @@ namespace Microsoft.PowerShell.Commands EnumerationOptions enumOptions = new EnumerationOptions(); enumOptions.EnumerateDeep = true; enumOptions.UseAmendedQualifiers = this.Amended; - searcher = new ManagementObjectSearcher(scope, classQuery, enumOptions); + var searcher = new ManagementObjectSearcher(scope, classQuery, enumOptions); return searcher; } /// diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 670802470..9fcdaee29 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -232,7 +232,7 @@ namespace Microsoft.PowerShell.Commands { if (o == null) { - return o; + return null; } PSObject pso = PSObject.AsPSObject(o); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index d7a092fc4..5dd3823bb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -2535,8 +2535,6 @@ function Get-PSImplicitRemotingSession /// private string GenerateConnectionStringForNewRunspace() { - string connectionString = null; - WSManConnectionInfo connectionInfo = _remoteRunspaceInfo.Runspace.ConnectionInfo as WSManConnectionInfo; if (null == connectionInfo) { @@ -2556,7 +2554,7 @@ function Get-PSImplicitRemotingSession CodeGeneration.EscapeSingleQuotedStringContent(containerConnectionInfo.ContainerProc.ContainerId)); } - return connectionString; + return null; } if (connectionInfo.UseDefaultWSManPort) diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseFormattingCommand.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseFormattingCommand.cs index 47d69d012..c2c3e4385 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseFormattingCommand.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/BaseFormattingCommand.cs @@ -603,7 +603,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format Nullable retVal = null; if (string.IsNullOrEmpty(Expand)) { - return retVal; + return null; } EnumerableExpansion temp; diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs index b9f3cba8f..7fa3ae64b 100644 --- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs +++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs @@ -3910,7 +3910,7 @@ namespace System.Management.Automation { ParameterBindingException bindingException = new ParameterBindingException( - error, + null, ErrorCategory.InvalidArgument, this.Command.MyInvocation, GetErrorExtent(argument), diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index 04284b1e9..fa292025b 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -1132,7 +1132,7 @@ namespace System.Management.Automation List result = null; var expandableString = lastAst as ExpandableStringExpressionAst; var constantString = lastAst as StringConstantExpressionAst; - if (constantString == null && expandableString == null) { return result; } + if (constantString == null && expandableString == null) { return null; } string strValue = constantString != null ? constantString.Value : expandableString.Value; StringConstantType strType = constantString != null ? constantString.StringConstantType : expandableString.StringConstantType; diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 8d00006e0..ed73de847 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -278,8 +278,7 @@ namespace System.Management.Automation.Language /// The StaticBindingResult that represents the binding. public static StaticBindingResult BindCommand(CommandAst commandAst, bool resolve) { - string[] desiredParameters = null; - return BindCommand(commandAst, resolve, desiredParameters); + return BindCommand(commandAst, resolve, null); } /// diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 0b0ac2ee2..0f2f24e73 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -1001,8 +1001,7 @@ namespace System.Management.Automation // Try the module-qualified auto-loading (unless module auto-loading has been entirely disabled) if (moduleAutoLoadingPreference != PSModuleAutoLoadingPreference.None) { - result = TryModuleAutoLoading(commandName, context, originalCommandName, commandOrigin, result, - ref lastError); + result = TryModuleAutoLoading(commandName, context, originalCommandName, commandOrigin, ref lastError); } if (result != null) @@ -1019,8 +1018,7 @@ namespace System.Management.Automation // Otherwise, invoke the CommandNotFound handler if (result == null) { - result = InvokeCommandNotFoundHandler(commandName, context, originalCommandName, commandOrigin, - result); + result = InvokeCommandNotFoundHandler(commandName, context, originalCommandName, commandOrigin); } } while (false); } @@ -1148,8 +1146,9 @@ namespace System.Management.Automation } - private static CommandInfo InvokeCommandNotFoundHandler(string commandName, ExecutionContext context, string originalCommandName, CommandOrigin commandOrigin, CommandInfo result) + private static CommandInfo InvokeCommandNotFoundHandler(string commandName, ExecutionContext context, string originalCommandName, CommandOrigin commandOrigin) { + CommandInfo result = null; CommandLookupEventArgs eventArgs; System.EventHandler cmdNotFoundHandler = context.EngineIntrinsics.InvokeCommand.CommandNotFoundAction; if (cmdNotFoundHandler != null) @@ -1349,8 +1348,10 @@ namespace System.Management.Automation return result; } - private static CommandInfo TryModuleAutoLoading(string commandName, ExecutionContext context, string originalCommandName, CommandOrigin commandOrigin, CommandInfo result, ref Exception lastError) + private static CommandInfo TryModuleAutoLoading(string commandName, ExecutionContext context, string originalCommandName, CommandOrigin commandOrigin, ref Exception lastError) { + CommandInfo result = null; + // If commandName was module-qualified. In that case, we should load the module. var colonOrBackslash = commandName.IndexOfAny(Utils.Separators.ColonOrBackslash); diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 01ae5f872..0e48d329d 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1004,7 +1004,7 @@ namespace System.Management.Automation if (PSSnapinQualifiedCommandName == null) { - return result; + return null; } WildcardPattern cmdletMatcher = diff --git a/src/System.Management.Automation/engine/DscResourceSearcher.cs b/src/System.Management.Automation/engine/DscResourceSearcher.cs index 2581676f6..cdef87ced 100644 --- a/src/System.Management.Automation/engine/DscResourceSearcher.cs +++ b/src/System.Management.Automation/engine/DscResourceSearcher.cs @@ -120,8 +120,6 @@ namespace System.Management.Automation /// Next DscResource Info object or null if none are found. private DscResourceInfo GetNextDscResource() { - DscResourceInfo returnValue = null; - var ps = PowerShell.Create(RunspaceMode.CurrentRunspace).AddCommand("Get-DscResource"); WildcardPattern resourceMatcher = WildcardPattern.Get(_resourceName, WildcardOptions.IgnoreCase); @@ -195,7 +193,7 @@ namespace System.Management.Automation if (matchFound) _matchingResource = _matchingResourceList.GetEnumerator(); else - return returnValue; + return null; }//if if (!_matchingResource.MoveNext()) @@ -204,10 +202,10 @@ namespace System.Management.Automation } else { - returnValue = _matchingResource.Current; + return _matchingResource.Current; } - return returnValue; + return null; } #endregion diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 854954b58..86c880a20 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -665,13 +665,13 @@ namespace Microsoft.PowerShell.Commands { // No extension so we'll have to search using the extensions // - if (VerifyIfNestedModuleIsAvailable(moduleSpecification, rootedPath, extension, out tempModuleInfoFromVerification)) + if (VerifyIfNestedModuleIsAvailable(moduleSpecification, rootedPath, /*extension*/null, out tempModuleInfoFromVerification)) { module = LoadUsingExtensions( parentModule, moduleSpecification.Name, rootedPath, // fileBaseName - extension, + /*extension*/null, moduleBase, // not using base from tempModuleInfoFromVerification as we are looking under moduleBase directory prefix, ss, @@ -689,13 +689,13 @@ namespace Microsoft.PowerShell.Commands { string newRootedPath = Path.Combine(rootedPath, moduleSpecification.Name); string newModuleBase = Path.Combine(moduleBase, moduleSpecification.Name); - if (VerifyIfNestedModuleIsAvailable(moduleSpecification, newRootedPath, extension, out tempModuleInfoFromVerification)) + if (VerifyIfNestedModuleIsAvailable(moduleSpecification, newRootedPath, /*extension*/null, out tempModuleInfoFromVerification)) { module = LoadUsingExtensions( parentModule, moduleSpecification.Name, newRootedPath, // fileBaseName - extension, + /*extension*/ null, newModuleBase, // not using base from tempModuleInfoFromVerification as we are looking under moduleBase directory prefix, ss, diff --git a/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs b/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs index 3faca3838..54274c518 100644 --- a/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs @@ -139,7 +139,7 @@ namespace System.Management.Automation AliasInfo result = null; if (String.IsNullOrEmpty(aliasName)) { - return result; + return null; } @@ -226,7 +226,7 @@ namespace System.Management.Automation AliasInfo result = null; if (String.IsNullOrEmpty(aliasName)) { - return result; + return null; } SessionStateScope scope = GetScopeByID(scopeID); diff --git a/src/System.Management.Automation/engine/SessionStateCmdletAPIs.cs b/src/System.Management.Automation/engine/SessionStateCmdletAPIs.cs index fef9b35a6..c6e8e872e 100644 --- a/src/System.Management.Automation/engine/SessionStateCmdletAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateCmdletAPIs.cs @@ -53,7 +53,7 @@ namespace System.Management.Automation CmdletInfo result = null; if (String.IsNullOrEmpty(cmdletName)) { - return result; + return null; } // Use the scope enumerator to find the alias using the @@ -122,7 +122,7 @@ namespace System.Management.Automation CmdletInfo result = null; if (String.IsNullOrEmpty(cmdletName)) { - return result; + return null; } SessionStateScope scope = GetScopeByID(scopeID); diff --git a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs index 8e50846af..9e6d94bdd 100644 --- a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs @@ -696,7 +696,7 @@ namespace System.Management.Automation if (!IsProviderLoaded(this.ExecutionContext.ProviderNames.FileSystem)) { s_tracer.WriteLine("The {0} provider is not loaded", this.ExecutionContext.ProviderNames.FileSystem); - return result; + return null; } // Since the drive does exist, add it. diff --git a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs index 09f23acec..10815782c 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs @@ -1650,7 +1650,7 @@ namespace System.Management.Automation Object deserialized = PSSerializer.Deserialize(PSSerializer.Serialize(value)); if (deserialized == null) { - return (PSObject)deserialized; + return null; } else { diff --git a/src/System.Management.Automation/engine/hostifaces/Parameter.cs b/src/System.Management.Automation/engine/hostifaces/Parameter.cs index 16ae1d59f..671dde82e 100644 --- a/src/System.Management.Automation/engine/hostifaces/Parameter.cs +++ b/src/System.Management.Automation/engine/hostifaces/Parameter.cs @@ -58,7 +58,7 @@ namespace System.Management.Automation.Runspaces } else { - Name = name; + Name = null; } Value = value; } diff --git a/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs b/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs index f58a63ca3..9db972d35 100644 --- a/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs +++ b/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs @@ -92,9 +92,8 @@ namespace Microsoft.CodeAnalysis ProcessorArchitecture[] architectureFilter) { IAssemblyEnum enumerator; - FusionAssemblyIdentity.IApplicationContext applicationContext = null; - int hr = CreateAssemblyEnum(out enumerator, applicationContext, partialNameFilter, ASM_CACHE.GAC, IntPtr.Zero); + int hr = CreateAssemblyEnum(out enumerator, null, partialNameFilter, ASM_CACHE.GAC, IntPtr.Zero); if (hr == S_FALSE) { // no assembly found @@ -120,6 +119,7 @@ namespace Microsoft.CodeAnalysis { FusionAssemblyIdentity.IAssemblyName nameObject; + FusionAssemblyIdentity.IApplicationContext applicationContext; hr = enumerator.GetNextAssembly(out applicationContext, out nameObject, 0); if (hr != 0) { diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs index 1748104db..f78fdeddb 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs @@ -407,7 +407,7 @@ namespace System.Management.Automation.Remoting { if (obj == null) { - return obj; + return null; } Dbg.Assert(type != null, "Expected type != null"); diff --git a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs index 7596d7a1f..ac0a9fe94 100644 --- a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs +++ b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs @@ -587,7 +587,7 @@ namespace System.Management.Automation.Remoting.Server internal override void WriteLine(string data) { - string dataToWrite = (data != null) ? _errorPrepend + data : data; + string dataToWrite = (data != null) ? _errorPrepend + data : null; base.WriteLine(dataToWrite); } @@ -679,7 +679,7 @@ namespace System.Management.Automation.Remoting.Server internal override void WriteLine(string data) { - string dataToWrite = (data != null) ? _errorPrepend + data : data; + string dataToWrite = (data != null) ? _errorPrepend + data : null; base.WriteLine(dataToWrite); } diff --git a/src/System.Management.Automation/help/DscResourceHelpProvider.cs b/src/System.Management.Automation/help/DscResourceHelpProvider.cs index f578e2238..54642f81f 100644 --- a/src/System.Management.Automation/help/DscResourceHelpProvider.cs +++ b/src/System.Management.Automation/help/DscResourceHelpProvider.cs @@ -208,12 +208,10 @@ namespace System.Management.Automation Dbg.Assert(resourceInfo != null, "Caller should verify that resourceInfo != null"); Dbg.Assert(helpFileToFind != null, "Caller should verify that helpFileToFind != null"); - HelpInfo result = null; - helpFile = MUIFileSearcher.LocateFile(helpFileToFind, searchPaths); if (!File.Exists(helpFile)) - return result; + return null; if (!String.IsNullOrEmpty(helpFile)) { @@ -223,10 +221,10 @@ namespace System.Management.Automation LoadHelpFile(helpFile, helpFile, resourceInfo.Name, reportErrors); } - result = GetFromResourceHelpCache(helpFile, Automation.HelpCategory.DscResource); + return GetFromResourceHelpCache(helpFile, Automation.HelpCategory.DscResource); } - return result; + return null; } /// diff --git a/src/System.Management.Automation/help/PSClassHelpProvider.cs b/src/System.Management.Automation/help/PSClassHelpProvider.cs index f2c432dac..be7740366 100644 --- a/src/System.Management.Automation/help/PSClassHelpProvider.cs +++ b/src/System.Management.Automation/help/PSClassHelpProvider.cs @@ -213,12 +213,10 @@ namespace System.Management.Automation Dbg.Assert(classInfo != null, "Caller should verify that classInfo != null"); Dbg.Assert(helpFileToFind != null, "Caller should verify that helpFileToFind != null"); - HelpInfo result = null; - helpFile = MUIFileSearcher.LocateFile(helpFileToFind, searchPaths); if (!File.Exists(helpFile)) - return result; + return null; if (!String.IsNullOrEmpty(helpFile)) { @@ -228,10 +226,10 @@ namespace System.Management.Automation LoadHelpFile(helpFile, helpFile, classInfo.Name, reportErrors); } - result = GetFromPSClasseHelpCache(helpFile, Automation.HelpCategory.Class); + return GetFromPSClasseHelpCache(helpFile, Automation.HelpCategory.Class); } - return result; + return null; } /// diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index 5c2fe6d67..0373627e1 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -268,8 +268,6 @@ namespace Microsoft.PowerShell.Commands if (ShouldProcess(resource, action)) { - string valueName = null; - // Get the registry item IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true); @@ -295,12 +293,12 @@ namespace Microsoft.PowerShell.Commands RegistryValueKind kind = dynParams.Type; - key.SetValue(valueName, value, kind); + key.SetValue(null, value, kind); valueSet = true; } catch (ArgumentException argException) { - WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, valueName)); + WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, null)); key.Close(); return; } @@ -338,7 +336,7 @@ namespace Microsoft.PowerShell.Commands try { // Set the value - key.SetValue(valueName, value); + key.SetValue(null, value); } catch (System.IO.IOException ioException) { @@ -375,7 +373,7 @@ namespace Microsoft.PowerShell.Commands // Since SetValue can munge the data to a specified // type (RegistryValueKind), retrieve the value again // to output it in the correct form to the user. - result = ReadExistingKeyValue(key, valueName); + result = ReadExistingKeyValue(key, null); key.Close(); WriteItemObject(result, path, false); @@ -4377,7 +4375,7 @@ namespace Microsoft.PowerShell.Commands RegistryProviderStrings.KeyDoesNotExist); WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path)); - return result; + return null; } } catch (ArgumentException argumentException)