Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,7 @@ protected override void BeginProcessing()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@ protected override void BeginProcessing()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,7 @@ protected override void ProcessRecord()
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ public UInt32 OperationTimeoutSec
/// </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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,7 @@ protected override void ProcessRecord()
}
}

CimNewCimInstance cimNewCimInstance = this.GetOperationAgent();
if (cimNewCimInstance == null)
{
cimNewCimInstance = CreateOperationAgent();
}
CimNewCimInstance cimNewCimInstance = this.GetOperationAgent() ?? CreateOperationAgent();

cimNewCimInstance.NewCimInstance(this);
cimNewCimInstance.ProcessActions(this.CmdletOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ public string QueryDialect
/// </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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ public SwitchParameter PassThru
/// </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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public override DataTemplate SelectTemplate(object item, System.Windows.Dependen
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,7 @@ internal static List<ShowCommandCommandInfo> GetCommandList(object[] commandObje
/// <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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,7 @@ private void LoadAssemblies(IEnumerable<string> assemblies)
{
// 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)
{
Expand Down
8 changes: 2 additions & 6 deletions src/Microsoft.WSMan.Management/CredSSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,13 @@ private void UpdateGPORegistrySettings(string applicationname, string[] delegate
{
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)
{
Expand Down
6 changes: 1 addition & 5 deletions src/Microsoft.WSMan.Management/WSManConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ protected override void BeginProcessing()
}
}

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))
{
Expand Down
6 changes: 1 addition & 5 deletions src/Microsoft.WSMan.Management/WsManHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,11 +960,7 @@ internal void CreateWsManConnection(string ParameterSetName, Uri connectionuri,

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);
}
Expand Down
31 changes: 8 additions & 23 deletions src/System.Management.Automation/engine/PSConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,38 +219,23 @@ internal void SetExperimentalFeatures(ConfigScope scope, string featureName, boo

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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,9 @@ private PSDriveInfo GetDrive(string name, bool automount)

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)
Expand Down Expand Up @@ -744,6 +740,9 @@ private PSDriveInfo AutomountFileSystemDrive(System.IO.DriveInfo systemDriveInfo
/// <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)
Expand Down
11 changes: 4 additions & 7 deletions src/System.Management.Automation/engine/lang/parserutils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,13 +1177,10 @@ internal static object MatchOperator(ExecutionContext context, IScriptExtent err

// 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)
Expand Down
12 changes: 3 additions & 9 deletions src/System.Management.Automation/help/HelpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,9 @@ internal string GetDefaultShellSearchPath()
{
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>
Expand Down