Refactoring - replace always null expressions with null

This commit is contained in:
PowerShell Team 2016-08-02 23:09:38 -07:00 committed by Jason Shirk (POWERSHELL)
parent c3ce30e34a
commit c1ee6c9d6d
23 changed files with 47 additions and 58 deletions

View file

@ -154,7 +154,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
else
{
sessionWasAlreadyTerminated = false;
return sessionException;
return null;
}
}

View file

@ -167,7 +167,6 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
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;
}
/// <summary>

View file

@ -232,7 +232,7 @@ namespace Microsoft.PowerShell.Commands
{
if (o == null)
{
return o;
return null;
}
PSObject pso = PSObject.AsPSObject(o);

View file

@ -2535,8 +2535,6 @@ function Get-PSImplicitRemotingSession
/// <returns></returns>
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)

View file

@ -603,7 +603,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
Nullable<EnumerableExpansion> retVal = null;
if (string.IsNullOrEmpty(Expand))
{
return retVal;
return null;
}
EnumerableExpansion temp;

View file

@ -3910,7 +3910,7 @@ namespace System.Management.Automation
{
ParameterBindingException bindingException =
new ParameterBindingException(
error,
null,
ErrorCategory.InvalidArgument,
this.Command.MyInvocation,
GetErrorExtent(argument),

View file

@ -1132,7 +1132,7 @@ namespace System.Management.Automation
List<CompletionResult> 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;

View file

@ -278,8 +278,7 @@ namespace System.Management.Automation.Language
/// <returns>The StaticBindingResult that represents the binding.</returns>
public static StaticBindingResult BindCommand(CommandAst commandAst, bool resolve)
{
string[] desiredParameters = null;
return BindCommand(commandAst, resolve, desiredParameters);
return BindCommand(commandAst, resolve, null);
}
/// <summary>

View file

@ -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<CommandLookupEventArgs> 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);

View file

@ -1004,7 +1004,7 @@ namespace System.Management.Automation
if (PSSnapinQualifiedCommandName == null)
{
return result;
return null;
}
WildcardPattern cmdletMatcher =

View file

@ -120,8 +120,6 @@ namespace System.Management.Automation
/// <returns>Next DscResource Info object or null if none are found.</returns>
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

View file

@ -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,

View file

@ -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);

View file

@ -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);

View file

@ -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.

View file

@ -1650,7 +1650,7 @@ namespace System.Management.Automation
Object deserialized = PSSerializer.Deserialize(PSSerializer.Serialize(value));
if (deserialized == null)
{
return (PSObject)deserialized;
return null;
}
else
{

View file

@ -58,7 +58,7 @@ namespace System.Management.Automation.Runspaces
}
else
{
Name = name;
Name = null;
}
Value = value;
}

View file

@ -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)
{

View file

@ -407,7 +407,7 @@ namespace System.Management.Automation.Remoting
{
if (obj == null)
{
return obj;
return null;
}
Dbg.Assert(type != null, "Expected type != null");

View file

@ -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);
}

View file

@ -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;
}
/// <summary>

View file

@ -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;
}
/// <summary>

View file

@ -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)