cleanup: Use coalesce expression (#12829)

This commit is contained in:
xtqqczze
2020-05-31 10:01:08 +05:00
committed by GitHub
parent 0d5b7f5e6f
commit 4e98011833
17 changed files with 35 additions and 112 deletions
@@ -248,11 +248,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
protected override void ProcessRecord()
{
base.CheckParameterSet();
CimGetAssociatedInstance operation = this.GetOperationAgent();
if (operation == null)
{
operation = this.CreateOperationAgent();
}
CimGetAssociatedInstance operation = this.GetOperationAgent() ?? this.CreateOperationAgent();
operation.GetCimAssociatedInstance(this);
operation.ProcessActions(this.CmdletOperation);
@@ -220,11 +220,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
protected override void ProcessRecord()
{
base.CheckParameterSet();
CimGetCimClass cimGetCimClass = this.GetOperationAgent();
if (cimGetCimClass == null)
{
cimGetCimClass = CreateOperationAgent();
}
CimGetCimClass cimGetCimClass = this.GetOperationAgent() ?? CreateOperationAgent();
cimGetCimClass.GetCimClass(this);
cimGetCimClass.ProcessActions(this.CmdletOperation);
@@ -460,11 +460,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
{
base.CheckParameterSet();
this.CheckArgument();
CimGetInstance cimGetInstance = this.GetOperationAgent();
if (cimGetInstance == null)
{
cimGetInstance = CreateOperationAgent();
}
CimGetInstance cimGetInstance = this.GetOperationAgent() ?? CreateOperationAgent();
cimGetInstance.GetCimInstance(this);
cimGetInstance.ProcessActions(this.CmdletOperation);
@@ -373,11 +373,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
/// </summary>
protected override void BeginProcessing()
{
CimInvokeCimMethod cimInvokeMethod = this.GetOperationAgent();
if (cimInvokeMethod == null)
{
cimInvokeMethod = CreateOperationAgent();
}
CimInvokeCimMethod cimInvokeMethod = this.GetOperationAgent() ?? CreateOperationAgent();
this.CmdletOperation = new CmdletOperationInvokeCimMethod(this, cimInvokeMethod);
this.AtBeginProcess = false;
@@ -355,11 +355,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
}
}
CimNewCimInstance cimNewCimInstance = this.GetOperationAgent();
if (cimNewCimInstance == null)
{
cimNewCimInstance = CreateOperationAgent();
}
CimNewCimInstance cimNewCimInstance = this.GetOperationAgent() ?? CreateOperationAgent();
cimNewCimInstance.NewCimInstance(this);
cimNewCimInstance.ProcessActions(this.CmdletOperation);
@@ -244,11 +244,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
/// </summary>
protected override void BeginProcessing()
{
CimRemoveCimInstance cimRemoveInstance = this.GetOperationAgent();
if (cimRemoveInstance == null)
{
cimRemoveInstance = CreateOperationAgent();
}
CimRemoveCimInstance cimRemoveInstance = this.GetOperationAgent() ?? CreateOperationAgent();
this.CmdletOperation = new CmdletOperationRemoveCimInstance(this, cimRemoveInstance);
this.AtBeginProcess = false;
@@ -301,11 +301,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
/// </summary>
protected override void BeginProcessing()
{
CimSetCimInstance cimSetCimInstance = this.GetOperationAgent();
if (cimSetCimInstance == null)
{
cimSetCimInstance = CreateOperationAgent();
}
CimSetCimInstance cimSetCimInstance = this.GetOperationAgent() ?? CreateOperationAgent();
this.CmdletOperation = new CmdletOperationSetCimInstance(this, cimSetCimInstance);
this.AtBeginProcess = false;
@@ -45,11 +45,7 @@ namespace Microsoft.Management.UI.Internal
return base.SelectTemplate(item, container);
}
Type type = item as Type;
if (type == null)
{
type = item.GetType();
}
Type type = item as Type ?? item.GetType();
DataTemplate template;
@@ -597,11 +597,7 @@ Function PSGetSerializedShowCommandInfo
/// <returns>An array of objects out of <paramref name="commandObjects"/>.</returns>
internal static object[] ObjectArrayFromObjectCollection(object commandObjects)
{
object[] objectArray = commandObjects as object[];
if (objectArray == null)
{
objectArray = ((System.Collections.ArrayList)commandObjects).ToArray();
}
object[] objectArray = commandObjects as object[] ?? ((System.Collections.ArrayList)commandObjects).ToArray();
return objectArray;
}
@@ -652,11 +652,7 @@ namespace Microsoft.PowerShell.Commands
{
// CoreCLR doesn't allow re-load TPA assemblies with different API (i.e. we load them by name and now want to load by path).
// LoadAssemblyHelper helps us avoid re-loading them, if they already loaded.
Assembly assembly = LoadAssemblyHelper(assemblyName);
if (assembly == null)
{
assembly = Assembly.LoadFrom(ResolveAssemblyName(assemblyName, false));
}
Assembly assembly = LoadAssemblyHelper(assemblyName) ?? Assembly.LoadFrom(ResolveAssemblyName(assemblyName, false));
if (PassThru)
{
+2 -6
View File
@@ -665,17 +665,13 @@ namespace Microsoft.WSMan.Management
{
string Registry_Path_Credentials_Delegation = Registry_Path + @"\CredentialsDelegation";
// open the registry key.If key is not present,create a new one
Credential_Delegation_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true);
if (Credential_Delegation_Key == null)
Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation, RegistryKeyPermissionCheck.ReadWriteSubTree);
Credential_Delegation_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true) ?? rootKey.CreateSubKey(Registry_Path_Credentials_Delegation, RegistryKeyPermissionCheck.ReadWriteSubTree);
Credential_Delegation_Key.SetValue(helper.Key_Allow_Fresh_Credentials, 1, RegistryValueKind.DWord);
Credential_Delegation_Key.SetValue(helper.Key_Concatenate_Defaults_AllowFresh, 1, RegistryValueKind.DWord);
// add the delegate value
Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true);
if (Allow_Fresh_Credential_Key == null)
Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, RegistryKeyPermissionCheck.ReadWriteSubTree);
Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true) ?? rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, RegistryKeyPermissionCheck.ReadWriteSubTree);
if (Allow_Fresh_Credential_Key != null)
{
@@ -269,11 +269,7 @@ namespace Microsoft.WSMan.Management
}
}
string crtComputerName = computername;
if (crtComputerName == null)
{
crtComputerName = "localhost";
}
string crtComputerName = computername ?? "localhost";
if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(this.SessionState.Drive.Current.Name + ":" + WSManStringLiterals.DefaultPathSeparator + crtComputerName, StringComparison.OrdinalIgnoreCase))
{
@@ -960,11 +960,7 @@ namespace Microsoft.WSMan.Management
IWSManSession m_session = CreateSessionObject(m_wsmanObject, authentication, sessionoption, credential, connectionStr, certificateThumbprint, usessl);
m_session.Identify(0);
string key = computername;
if (key == null)
{
key = "localhost";
}
string key = computername ?? "localhost";
AddtoDictionary(key, m_session);
}
@@ -219,38 +219,23 @@ namespace System.Management.Automation.Configuration
internal bool IsImplicitWinCompatEnabled()
{
bool? settingValue = ReadValueFromFile<bool?>(ConfigScope.CurrentUser, DisableImplicitWinCompatKey);
if (!settingValue.HasValue)
{
// if the setting is not mentioned in configuration files, then the default DisableImplicitWinCompat value is False
settingValue = ReadValueFromFile<bool?>(ConfigScope.AllUsers, DisableImplicitWinCompatKey, defaultValue: false);
}
bool settingValue = ReadValueFromFile<bool?>(ConfigScope.CurrentUser, DisableImplicitWinCompatKey)
?? ReadValueFromFile<bool?>(ConfigScope.AllUsers, DisableImplicitWinCompatKey)
?? false;
return !settingValue.Value;
return !settingValue;
}
internal string[] GetWindowsPowerShellCompatibilityModuleDenyList()
{
string[] settingValue = ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityModuleDenyListKey);
if (settingValue == null)
{
// if the setting is not mentioned in configuration files, then the default WindowsPowerShellCompatibilityModuleDenyList value is null
settingValue = ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityModuleDenyListKey);
}
return settingValue;
return ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityModuleDenyListKey)
?? ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityModuleDenyListKey);
}
internal string[] GetWindowsPowerShellCompatibilityNoClobberModuleList()
{
string[] settingValue = ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityNoClobberModuleListKey);
if (settingValue == null)
{
// if the setting is not mentioned in configuration files, then the default WindowsPowerShellCompatibilityNoClobberModuleList value is null
settingValue = ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityNoClobberModuleListKey);
}
return settingValue;
return ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityNoClobberModuleListKey)
?? ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityNoClobberModuleListKey);
}
/// <summary>
@@ -473,13 +473,9 @@ namespace System.Management.Automation
if (result == null && automount)
{
// first try to automount as a file system drive
result = AutomountFileSystemDrive(name);
// if it didn't work, then try automounting as a BuiltIn drive (e.g. "Cert"/"Certificate"/"WSMan")
if (result == null)
{
result = AutomountBuiltInDrive(name); // internally this calls GetDrive(name, false)
}
// Attempt to automount as a file system drive
// or as a BuiltIn drive (e.g. "Cert"/"Certificate"/"WSMan")
result = AutomountFileSystemDrive(name) ?? AutomountBuiltInDrive(name);
}
if (result == null)
@@ -744,6 +740,9 @@ namespace System.Management.Automation
/// <summary>
/// Auto-mounts a built-in drive.
/// </summary>
/// <remarks>
/// Calls GetDrive(name, false) internally.
/// </remarks>
/// <param name="name">The name of the drive to load.</param>
/// <returns></returns>
internal PSDriveInfo AutomountBuiltInDrive(string name)
@@ -1178,13 +1178,10 @@ namespace System.Management.Automation
// if passed an explicit regex, just use it
// otherwise compile the expression.
Regex r = PSObject.Base(rval) as Regex;
if (r == null)
{
// In this situation, creation of Regex should not fail. We are not
// processing ArgumentException in this case.
r = NewRegex(PSObject.ToStringParser(context, rval), reOptions);
}
// In this situation, creation of Regex should not fail. We are not
// processing ArgumentException in this case.
Regex r = PSObject.Base(rval) as Regex
?? NewRegex(PSObject.ToStringParser(context, rval), reOptions);
IEnumerator list = LanguagePrimitives.GetEnumerator(lval);
if (list == null)
@@ -225,15 +225,9 @@ namespace System.Management.Automation
{
string shellID = this.HelpSystem.ExecutionContext.ShellID;
// Beginning in PowerShell 6.0.0.12, the $pshome is no longer registry specified, we search the application base instead.
string returnValue = Utils.GetApplicationBase(shellID);
if (returnValue == null)
{
// use executing assemblies location in case registry entry not found
returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
}
return returnValue;
// We use executing assemblies location in case registry entry not found
return Utils.GetApplicationBase(shellID)
?? Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
}
/// <summary>