mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix IDE0090: Simplify new expression part 2 (#14200)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0090
This commit is contained in:
+7
-7
@@ -90,7 +90,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(cimException != null, "Caller should verify cimException != null");
|
||||
|
||||
string message = BuildErrorMessage(jobDescription, jobContext, cimException.Message);
|
||||
CimJobException cimJobException = new CimJobException(message, cimException);
|
||||
CimJobException cimJobException = new(message, cimException);
|
||||
cimJobException.InitializeErrorRecord(jobContext, cimException);
|
||||
return cimJobException;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
string message = BuildErrorMessage(jobDescription, jobContext, inner.Message);
|
||||
CimJobException cimJobException = new CimJobException(message, inner);
|
||||
CimJobException cimJobException = new(message, inner);
|
||||
var containsErrorRecord = inner as IContainsErrorRecord;
|
||||
if (containsErrorRecord != null)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
|
||||
Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");
|
||||
|
||||
CimJobException cimJobException = new CimJobException(jobContext.PrependComputerNameToMessage(message), inner);
|
||||
CimJobException cimJobException = new(jobContext.PrependComputerNameToMessage(message), inner);
|
||||
cimJobException.InitializeErrorRecord(jobContext, errorId, errorCategory);
|
||||
return cimJobException;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
|
||||
Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");
|
||||
|
||||
CimJobException cimJobException = new CimJobException(message, inner);
|
||||
CimJobException cimJobException = new(message, inner);
|
||||
cimJobException.InitializeErrorRecord(null, errorId, errorCategory);
|
||||
return cimJobException;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
string errorMessage = BuildErrorMessage(jobDescription, jobContext, rawErrorMessage);
|
||||
|
||||
CimJobException cje = new CimJobException(errorMessage);
|
||||
CimJobException cje = new(errorMessage);
|
||||
cje.InitializeErrorRecord(jobContext, "CimJob_" + methodName + "_" + errorCodeFromMethod, ErrorCategory.InvalidResult);
|
||||
|
||||
return cje;
|
||||
@@ -197,7 +197,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
|
||||
{
|
||||
ErrorRecord coreErrorRecord = new ErrorRecord(
|
||||
ErrorRecord coreErrorRecord = new(
|
||||
exception: exception,
|
||||
errorId: errorId,
|
||||
errorCategory: errorCategory,
|
||||
@@ -205,7 +205,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if (jobContext != null)
|
||||
{
|
||||
System.Management.Automation.Remoting.OriginInfo originInfo = new System.Management.Automation.Remoting.OriginInfo(
|
||||
System.Management.Automation.Remoting.OriginInfo originInfo = new(
|
||||
jobContext.Session.ComputerName,
|
||||
Guid.Empty);
|
||||
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
#region Getting tracker for a given cmdlet invocation
|
||||
|
||||
private static readonly ConditionalWeakTable<InvocationInfo, TerminatingErrorTracker> s_invocationToTracker =
|
||||
new ConditionalWeakTable<InvocationInfo, TerminatingErrorTracker>();
|
||||
new();
|
||||
|
||||
private static int GetNumberOfSessions(InvocationInfo invocationInfo)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region Tracking session's "connectivity" status
|
||||
|
||||
private readonly ConcurrentDictionary<CimSession, bool> _sessionToIsConnected = new ConcurrentDictionary<CimSession, bool>();
|
||||
private readonly ConcurrentDictionary<CimSession, bool> _sessionToIsConnected = new();
|
||||
|
||||
internal void MarkSessionAsConnected(CimSession connectedSession)
|
||||
{
|
||||
@@ -166,7 +166,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region Tracking session's "terminated" status
|
||||
|
||||
private readonly ConcurrentDictionary<CimSession, bool> _sessionToIsTerminated = new ConcurrentDictionary<CimSession, bool>();
|
||||
private readonly ConcurrentDictionary<CimSession, bool> _sessionToIsTerminated = new();
|
||||
|
||||
internal void MarkSessionAsTerminated(CimSession terminatedSession, out bool sessionWasAlreadyTerminated)
|
||||
{
|
||||
@@ -196,8 +196,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal CmdletMethodInvoker<bool> GetErrorReportingDelegate(ErrorRecord errorRecord)
|
||||
{
|
||||
ManualResetEventSlim manualResetEventSlim = new ManualResetEventSlim();
|
||||
object lockObject = new object();
|
||||
ManualResetEventSlim manualResetEventSlim = new();
|
||||
object lockObject = new();
|
||||
Func<Cmdlet, bool> action = (Cmdlet cmdlet) =>
|
||||
{
|
||||
_numberOfReportedSessionTerminatingErrors++;
|
||||
|
||||
+5
-5
@@ -57,7 +57,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
_jobSpecificCustomOptions = new Lazy<CimCustomOptionsDictionary>(this.CalculateJobSpecificCustomOptions);
|
||||
}
|
||||
|
||||
private readonly CimSensitiveValueConverter _cimSensitiveValueConverter = new CimSensitiveValueConverter();
|
||||
private readonly CimSensitiveValueConverter _cimSensitiveValueConverter = new();
|
||||
|
||||
internal CimSensitiveValueConverter CimSensitiveValueConverter { get { return _cimSensitiveValueConverter; } }
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly Random s_globalRandom = new Random();
|
||||
private static readonly Random s_globalRandom = new();
|
||||
private readonly Random _random;
|
||||
private int _sleepAndRetryDelayRangeMs = 1000;
|
||||
private int _sleepAndRetryExtraDelayMs = 0;
|
||||
@@ -543,7 +543,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region Controlling job state
|
||||
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
|
||||
/// <summary>
|
||||
/// Stops this job.
|
||||
@@ -578,7 +578,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
private readonly object _jobStateLock = new object();
|
||||
private readonly object _jobStateLock = new();
|
||||
private bool _jobHadErrors;
|
||||
private bool _jobWasStarted;
|
||||
private bool _jobWasStopped;
|
||||
@@ -730,7 +730,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region Support for progress reporting
|
||||
|
||||
private readonly ConcurrentDictionary<int, ProgressRecord> _activityIdToLastProgressRecord = new ConcurrentDictionary<int, ProgressRecord>();
|
||||
private readonly ConcurrentDictionary<int, ProgressRecord> _activityIdToLastProgressRecord = new();
|
||||
|
||||
internal override void WriteProgress(ProgressRecord progressRecord)
|
||||
{
|
||||
|
||||
+2
-2
@@ -76,7 +76,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
if (actionPreferenceComesFromCommandLineParameter)
|
||||
{
|
||||
Exception exception = new ArgumentException(message);
|
||||
ErrorRecord errorRecord = new ErrorRecord(exception, "ActionPreferenceNotSupportedByCimCmdletAdapter", ErrorCategory.NotImplemented, null);
|
||||
ErrorRecord errorRecord = new(exception, "ActionPreferenceNotSupportedByCimCmdletAdapter", ErrorCategory.NotImplemented, null);
|
||||
cmdlet.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Lazy<CimSession> _defaultCimSession = new Lazy<CimSession>(CreateDefaultCimSession);
|
||||
private readonly Lazy<CimSession> _defaultCimSession = new(CreateDefaultCimSession);
|
||||
|
||||
private static CimSession CreateDefaultCimSession()
|
||||
{
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ namespace Microsoft.PowerShell.Cim
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<IDisposable> _trackedDisposables = new List<IDisposable>();
|
||||
private readonly List<IDisposable> _trackedDisposables = new();
|
||||
|
||||
/// <summary>
|
||||
/// Releases resources associated with this object.
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal class CimCustomOptionsDictionary
|
||||
{
|
||||
private readonly IDictionary<string, object> _dict;
|
||||
private readonly object _dictModificationLock = new object();
|
||||
private readonly object _dictModificationLock = new();
|
||||
|
||||
private CimCustomOptionsDictionary(IEnumerable<KeyValuePair<string, object>> wrappedDictionary)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return new CimCustomOptionsDictionary(wrappedDictionary);
|
||||
}
|
||||
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary> s_cimInstanceToCustomOptions = new ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary>();
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary> s_cimInstanceToCustomOptions = new();
|
||||
|
||||
internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
|
||||
{
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
private string _resultRole;
|
||||
private string _sourceRole;
|
||||
|
||||
internal readonly Dictionary<string, object> queryOptions = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
internal readonly Dictionary<string, object> queryOptions = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
internal ClientSideQuery ClientSideQuery { get; }
|
||||
|
||||
|
||||
+4
-4
@@ -281,7 +281,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
cimSession.ComputerName,
|
||||
nameOfUnsupportedSwitch);
|
||||
Exception exception = new NotSupportedException(errorMessage);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
exception,
|
||||
"NoExtendedSemanticsSupportInRemoteDcomProtocol",
|
||||
ErrorCategory.NotImplemented,
|
||||
@@ -338,7 +338,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region Session affinity management
|
||||
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimSession> s_cimInstanceToSessionOfOrigin = new ConditionalWeakTable<CimInstance, CimSession>();
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimSession> s_cimInstanceToSessionOfOrigin = new();
|
||||
|
||||
internal static void AssociateSessionOfOriginWithInstance(CimInstance cimInstance, CimSession sessionOfOrigin)
|
||||
{
|
||||
@@ -394,10 +394,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if (this.CmdletDefinitionContext.ExposeCimNamespaceParameter)
|
||||
{
|
||||
Collection<Attribute> namespaceAttributes = new Collection<Attribute>();
|
||||
Collection<Attribute> namespaceAttributes = new();
|
||||
namespaceAttributes.Add(new ValidateNotNullOrEmptyAttribute());
|
||||
namespaceAttributes.Add(new ParameterAttribute());
|
||||
RuntimeDefinedParameter namespaceRuntimeParameter = new RuntimeDefinedParameter(
|
||||
RuntimeDefinedParameter namespaceRuntimeParameter = new(
|
||||
CimNamespaceParameter,
|
||||
typeof(string),
|
||||
namespaceAttributes);
|
||||
|
||||
+3
-3
@@ -153,7 +153,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
private abstract class CimInstancePropertyBasedFilter : CimInstanceFilterBase
|
||||
{
|
||||
private readonly List<PropertyValueFilter> _propertyValueFilters = new List<PropertyValueFilter>();
|
||||
private readonly List<PropertyValueFilter> _propertyValueFilters = new();
|
||||
|
||||
protected IEnumerable<PropertyValueFilter> PropertyValueFilters { get { return _propertyValueFilters; } }
|
||||
|
||||
@@ -624,8 +624,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
private int _numberOfResultsFromMi;
|
||||
private int _numberOfMatchingResults;
|
||||
|
||||
private readonly List<CimInstanceFilterBase> _filters = new List<CimInstanceFilterBase>();
|
||||
private readonly object _myLock = new object();
|
||||
private readonly List<CimInstanceFilterBase> _filters = new();
|
||||
private readonly object _myLock = new();
|
||||
|
||||
#region "Public" interface for client-side filtering
|
||||
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Exception e) // Catch-all OK, 3rd party callout
|
||||
{
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderSeekError",
|
||||
SessionStateStrings.ProviderSeekError,
|
||||
holder.PathInfo.Provider,
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
var type = typeof(T);
|
||||
const BindingFlags binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
T rv = new T();
|
||||
T rv = new();
|
||||
|
||||
using (var instance = session.QueryFirstInstance(nameSpace, CIMHelper.WqlQueryAll(wmiClassName)))
|
||||
{
|
||||
@@ -148,7 +148,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
foreach (var instance in instances)
|
||||
{
|
||||
T objT = new T();
|
||||
T objT = new();
|
||||
|
||||
using (instance)
|
||||
{
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </returns>
|
||||
internal override object GetDynamicParameters(CmdletProviderContext context)
|
||||
{
|
||||
Collection<string> propertyCollection = new Collection<string>();
|
||||
Collection<string> propertyCollection = new();
|
||||
propertyCollection.Add(_property);
|
||||
|
||||
if (Path != null && Path.Length > 0)
|
||||
@@ -124,7 +124,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
currentContext.PassThru = PassThru;
|
||||
|
||||
Collection<string> propertyCollection = new Collection<string>();
|
||||
Collection<string> propertyCollection = new();
|
||||
propertyCollection.Add(_property);
|
||||
|
||||
foreach (string path in Path)
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
statusDescription = string.Format(CultureInfo.InvariantCulture, ClearRecycleBinResources.ClearRecycleBinStatusDescriptionByDrive, drivePath);
|
||||
}
|
||||
|
||||
ProgressRecord progress = new ProgressRecord(0, activity, statusDescription);
|
||||
ProgressRecord progress = new(0, activity, statusDescription);
|
||||
progress.PercentComplete = 30;
|
||||
progress.RecordType = ProgressRecordType.Processing;
|
||||
WriteProgress(progress);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Microsoft.PowerShell.Commands.Internal
|
||||
string args,
|
||||
string stdin = "")
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
ProcessStartInfo startInfo = new();
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.RedirectStandardInput = true;
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
@@ -30,7 +30,7 @@ namespace Microsoft.PowerShell.Commands.Internal
|
||||
startInfo.Arguments = args;
|
||||
string stdout;
|
||||
|
||||
using (Process process = new Process())
|
||||
using (Process process = new())
|
||||
{
|
||||
process.StartInfo = startInfo;
|
||||
try
|
||||
|
||||
@@ -194,9 +194,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("CN", "__SERVER", "Server", "IPAddress")]
|
||||
public string[] ComputerName { get; set; } = new string[] { "." };
|
||||
|
||||
private List<string> _validatedComputerNames = new List<string>();
|
||||
private readonly List<string> _waitOnComputers = new List<string>();
|
||||
private readonly HashSet<string> _uniqueComputerNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
private List<string> _validatedComputerNames = new();
|
||||
private readonly List<string> _waitOnComputers = new();
|
||||
private readonly HashSet<string> _uniqueComputerNames = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// The following is the definition of the input parameter "Credential".
|
||||
@@ -336,13 +336,13 @@ $result
|
||||
/// Indicate to exit.
|
||||
/// </summary>
|
||||
private bool _exit, _timeUp;
|
||||
private readonly CancellationTokenSource _cancel = new CancellationTokenSource();
|
||||
private readonly CancellationTokenSource _cancel = new();
|
||||
|
||||
/// <summary>
|
||||
/// A waithandler to wait on. Current thread will wait on it during the delay interval.
|
||||
/// </summary>
|
||||
private readonly ManualResetEventSlim _waitHandler = new ManualResetEventSlim(false);
|
||||
private readonly Dictionary<string, ComputerInfo> _computerInfos = new Dictionary<string, ComputerInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ManualResetEventSlim _waitHandler = new(false);
|
||||
private readonly Dictionary<string, ComputerInfo> _computerInfos = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// CLR 4.0 Port note - use https://msdn.microsoft.com/library/system.net.networkinformation.ipglobalproperties.hostname(v=vs.110).aspx
|
||||
private readonly string _shortLocalMachineName = Dns.GetHostName();
|
||||
@@ -441,7 +441,7 @@ $result
|
||||
if (!InternalTestHooks.TestWaitStopComputer && Wait && containLocalhost)
|
||||
{
|
||||
// The local machine will be ignored, and an error will be emitted.
|
||||
InvalidOperationException ex = new InvalidOperationException(ComputerResources.CannotWaitLocalComputer);
|
||||
InvalidOperationException ex = new(ComputerResources.CannotWaitLocalComputer);
|
||||
WriteError(new ErrorRecord(ex, "CannotWaitLocalComputer", ErrorCategory.InvalidOperation, null));
|
||||
containLocalhost = false;
|
||||
}
|
||||
@@ -463,7 +463,7 @@ $result
|
||||
/// <param name="progressRecordType"></param>
|
||||
private void WriteProgress(string activity, string status, int percent, ProgressRecordType progressRecordType)
|
||||
{
|
||||
ProgressRecord progress = new ProgressRecord(_activityId, activity, status);
|
||||
ProgressRecord progress = new(_activityId, activity, status);
|
||||
progress.PercentComplete = percent;
|
||||
progress.RecordType = progressRecordType;
|
||||
WriteProgress(progress);
|
||||
@@ -725,7 +725,7 @@ $result
|
||||
/// <returns></returns>
|
||||
internal static List<string> TestPowerShell(List<string> computerNames, List<string> nextTestList, System.Management.Automation.PowerShell powershell, PSCredential credential)
|
||||
{
|
||||
List<string> psList = new List<string>();
|
||||
List<string> psList = new();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -783,7 +783,7 @@ $result
|
||||
// Timeout, For, Delay, Progress cannot be present if Wait is not present
|
||||
if ((_timeoutSpecified || _waitForSpecified || _delaySpecified) && !Wait)
|
||||
{
|
||||
InvalidOperationException ex = new InvalidOperationException(ComputerResources.RestartComputerInvalidParameter);
|
||||
InvalidOperationException ex = new(ComputerResources.RestartComputerInvalidParameter);
|
||||
ThrowTerminatingError(new ErrorRecord(ex, "RestartComputerInvalidParameter", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
|
||||
@@ -810,8 +810,8 @@ $result
|
||||
_powershell.AddScript(TestPowershellScript);
|
||||
break;
|
||||
default:
|
||||
InvalidOperationException ex = new InvalidOperationException(ComputerResources.NoSupportForCombinedServiceType);
|
||||
ErrorRecord error = new ErrorRecord(ex, "NoSupportForCombinedServiceType", ErrorCategory.InvalidOperation, (int)_waitFor);
|
||||
InvalidOperationException ex = new(ComputerResources.NoSupportForCombinedServiceType);
|
||||
ErrorRecord error = new(ex, "NoSupportForCombinedServiceType", ErrorCategory.InvalidOperation, (int)_waitFor);
|
||||
ThrowTerminatingError(error);
|
||||
break;
|
||||
}
|
||||
@@ -1117,7 +1117,7 @@ $result
|
||||
{
|
||||
#region Private Members
|
||||
|
||||
private readonly CancellationTokenSource _cancel = new CancellationTokenSource();
|
||||
private readonly CancellationTokenSource _cancel = new();
|
||||
|
||||
private const int forcedShutdown = 5; // See https://msdn.microsoft.com/library/aa394058(v=vs.85).aspx
|
||||
|
||||
@@ -1388,7 +1388,7 @@ $result
|
||||
{
|
||||
bool isLocalhost = targetComputer.Equals(ComputerWMIHelper.localhostStr, StringComparison.OrdinalIgnoreCase);
|
||||
string errMsg = StringUtil.Format(ComputerResources.InvalidNewName, isLocalhost ? _shortLocalMachineName : targetComputer, NewName);
|
||||
ErrorRecord error = new ErrorRecord(
|
||||
ErrorRecord error = new(
|
||||
new InvalidOperationException(errMsg), "InvalidNewName",
|
||||
ErrorCategory.InvalidArgument, NewName);
|
||||
WriteError(error);
|
||||
@@ -1430,7 +1430,7 @@ $result
|
||||
|
||||
try
|
||||
{
|
||||
using (CancellationTokenSource cancelTokenSource = new CancellationTokenSource())
|
||||
using (CancellationTokenSource cancelTokenSource = new())
|
||||
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, credToUse, WsmanAuthentication, isLocalhost, this, cancelTokenSource.Token))
|
||||
{
|
||||
var operationOptions = new CimOperationOptions
|
||||
@@ -1453,7 +1453,7 @@ $result
|
||||
if (oldName.Equals(newName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string errMsg = StringUtil.Format(ComputerResources.NewNameIsOldName, computerName, newName);
|
||||
ErrorRecord error = new ErrorRecord(
|
||||
ErrorRecord error = new(
|
||||
new InvalidOperationException(errMsg), "NewNameIsOldName",
|
||||
ErrorCategory.InvalidArgument, newName);
|
||||
WriteError(error);
|
||||
@@ -1512,7 +1512,7 @@ $result
|
||||
{
|
||||
var ex = new Win32Exception(retVal);
|
||||
string errMsg = StringUtil.Format(ComputerResources.FailToRename, computerName, newName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "FailToRenameComputer", ErrorCategory.OperationStopped, computerName);
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), "FailToRenameComputer", ErrorCategory.OperationStopped, computerName);
|
||||
WriteError(error);
|
||||
}
|
||||
else
|
||||
@@ -1553,14 +1553,14 @@ $result
|
||||
catch (CimException ex)
|
||||
{
|
||||
string errMsg = StringUtil.Format(ComputerResources.FailToConnectToComputer, computerName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "RenameComputerException",
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), "RenameComputerException",
|
||||
ErrorCategory.OperationStopped, computerName);
|
||||
WriteError(error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string errMsg = StringUtil.Format(ComputerResources.FailToConnectToComputer, computerName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "RenameComputerException",
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), "RenameComputerException",
|
||||
ErrorCategory.OperationStopped, computerName);
|
||||
WriteError(error);
|
||||
}
|
||||
@@ -1844,7 +1844,7 @@ $result
|
||||
/// <returns></returns>
|
||||
internal static string GetScopeString(string computer, string namespaceParameter)
|
||||
{
|
||||
StringBuilder returnValue = new StringBuilder("\\\\");
|
||||
StringBuilder returnValue = new("\\\\");
|
||||
if (computer.Equals("::1", StringComparison.OrdinalIgnoreCase) || computer.Equals("[::1]", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
returnValue.Append("localhost");
|
||||
@@ -1920,7 +1920,7 @@ $result
|
||||
}
|
||||
|
||||
string compname = string.Empty;
|
||||
StringBuilder strComputers = new StringBuilder();
|
||||
StringBuilder strComputers = new();
|
||||
int i = 0;
|
||||
foreach (string computer in computerNames)
|
||||
{
|
||||
@@ -1950,7 +1950,7 @@ $result
|
||||
|
||||
internal static ComputerChangeInfo GetComputerStatusObject(int errorcode, string computername)
|
||||
{
|
||||
ComputerChangeInfo computerchangeinfo = new ComputerChangeInfo();
|
||||
ComputerChangeInfo computerchangeinfo = new();
|
||||
computerchangeinfo.ComputerName = computername;
|
||||
if (errorcode != 0)
|
||||
{
|
||||
@@ -1966,7 +1966,7 @@ $result
|
||||
|
||||
internal static RenameComputerChangeInfo GetRenameComputerStatusObject(int errorcode, string newcomputername, string oldcomputername)
|
||||
{
|
||||
RenameComputerChangeInfo renamecomputerchangeinfo = new RenameComputerChangeInfo();
|
||||
RenameComputerChangeInfo renamecomputerchangeinfo = new();
|
||||
renamecomputerchangeinfo.OldComputerName = oldcomputername;
|
||||
renamecomputerchangeinfo.NewComputerName = newcomputername;
|
||||
if (errorcode != 0)
|
||||
@@ -1983,7 +1983,7 @@ $result
|
||||
|
||||
internal static void WriteNonTerminatingError(int errorcode, PSCmdlet cmdlet, string computername)
|
||||
{
|
||||
Win32Exception ex = new Win32Exception(errorcode);
|
||||
Win32Exception ex = new(errorcode);
|
||||
string additionalmessage = string.Empty;
|
||||
if (ex.NativeErrorCode.Equals(0x00000035))
|
||||
{
|
||||
@@ -1991,7 +1991,7 @@ $result
|
||||
}
|
||||
|
||||
string message = StringUtil.Format(ComputerResources.OperationFailed, ex.Message, computername, additionalmessage);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, computername);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, computername);
|
||||
cmdlet.WriteError(er);
|
||||
}
|
||||
|
||||
@@ -2101,7 +2101,7 @@ $result
|
||||
string message =
|
||||
StringUtil.Format(ComputerResources.PrivilegeNotEnabled, computerName,
|
||||
isLocalhost ? ComputerWMIHelper.SE_SHUTDOWN_NAME : ComputerWMIHelper.SE_REMOTE_SHUTDOWN_NAME);
|
||||
ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(message), "PrivilegeNotEnabled", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord errorRecord = new(new InvalidOperationException(message), "PrivilegeNotEnabled", ErrorCategory.InvalidOperation, null);
|
||||
cmdlet.WriteError(errorRecord);
|
||||
return false;
|
||||
}
|
||||
@@ -2159,7 +2159,7 @@ $result
|
||||
{
|
||||
var ex = new Win32Exception(retVal);
|
||||
string errMsg = StringUtil.Format(formatErrorMessage, computerName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(
|
||||
ErrorRecord error = new(
|
||||
new InvalidOperationException(errMsg), ErrorFQEID, ErrorCategory.OperationStopped, computerName);
|
||||
cmdlet.WriteError(error);
|
||||
}
|
||||
@@ -2172,14 +2172,14 @@ $result
|
||||
catch (CimException ex)
|
||||
{
|
||||
string errMsg = StringUtil.Format(formatErrorMessage, computerName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), ErrorFQEID,
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), ErrorFQEID,
|
||||
ErrorCategory.OperationStopped, computerName);
|
||||
cmdlet.WriteError(error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string errMsg = StringUtil.Format(formatErrorMessage, computerName, ex.Message);
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), ErrorFQEID,
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), ErrorFQEID,
|
||||
ErrorCategory.OperationStopped, computerName);
|
||||
cmdlet.WriteError(error);
|
||||
}
|
||||
|
||||
+9
-9
@@ -108,7 +108,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// An array of content holder objects that contain the path information
|
||||
/// and content readers/writers for the item represented by the path information.
|
||||
/// </summary>
|
||||
internal List<ContentHolder> contentStreams = new List<ContentHolder>();
|
||||
internal List<ContentHolder> contentStreams = new();
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the content into a PSObject and adds context information as notes.
|
||||
@@ -297,7 +297,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// Construct a provider qualified path as the Path note
|
||||
|
||||
PSNoteProperty note = new PSNoteProperty("PSPath", PSPath);
|
||||
PSNoteProperty note = new("PSPath", PSPath);
|
||||
content.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSPath", PSPath);
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// and write out an error.
|
||||
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentCloseError",
|
||||
SessionStateStrings.ProviderContentCloseError,
|
||||
holder.PathInfo.Provider,
|
||||
@@ -422,7 +422,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// and write out an error.
|
||||
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentCloseError",
|
||||
SessionStateStrings.ProviderContentCloseError,
|
||||
holder.PathInfo.Provider,
|
||||
@@ -480,7 +480,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Create the results array
|
||||
|
||||
List<ContentHolder> results = new List<ContentHolder>();
|
||||
List<ContentHolder> results = new();
|
||||
|
||||
foreach (PathInfo pathInfo in pathInfos)
|
||||
{
|
||||
@@ -538,7 +538,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (readers.Count == 1 && readers[0] != null)
|
||||
{
|
||||
ContentHolder holder =
|
||||
new ContentHolder(pathInfo, readers[0], null);
|
||||
new(pathInfo, readers[0], null);
|
||||
|
||||
results.Add(holder);
|
||||
}
|
||||
@@ -573,7 +573,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
bool allowEmptyResult,
|
||||
CmdletProviderContext currentCommandContext)
|
||||
{
|
||||
Collection<PathInfo> results = new Collection<PathInfo>();
|
||||
Collection<PathInfo> results = new();
|
||||
|
||||
foreach (string path in pathsToResolve)
|
||||
{
|
||||
@@ -653,7 +653,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
out drive);
|
||||
|
||||
PathInfo pathInfo =
|
||||
new PathInfo(
|
||||
new(
|
||||
drive,
|
||||
provider,
|
||||
unresolvedPath,
|
||||
@@ -666,7 +666,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// Detect if the path resolution failed to resolve to a file.
|
||||
string error = StringUtil.Format(NavigationResources.ItemNotFound, Path);
|
||||
Exception e = new Exception(error);
|
||||
Exception e = new(error);
|
||||
|
||||
pathNotFoundErrorRecord = new ErrorRecord(
|
||||
e,
|
||||
|
||||
+2
-2
@@ -225,7 +225,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </param>
|
||||
private void UpdateProgress(string status)
|
||||
{
|
||||
ProgressRecord progress = new ProgressRecord(0, activity, status ?? ComputerResources.ProgressStatusCompleted);
|
||||
ProgressRecord progress = new(0, activity, status ?? ComputerResources.ProgressStatusCompleted);
|
||||
progress.RecordType = status == null ? ProgressRecordType.Completed : ProgressRecordType.Processing;
|
||||
|
||||
WriteProgress(progress);
|
||||
@@ -486,7 +486,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </returns>
|
||||
private static HyperVInfo GetHyperVisorInfo(CimSession session)
|
||||
{
|
||||
HyperVInfo info = new HyperVInfo();
|
||||
HyperVInfo info = new();
|
||||
bool ok = false;
|
||||
CimInstance instance = null;
|
||||
|
||||
|
||||
+5
-5
@@ -116,7 +116,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_totalCountSpecified && _tailSpecified)
|
||||
{
|
||||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail");
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(error);
|
||||
return;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_tailSpecified && holder.Reader is not FileSystemContentReaderWriter)
|
||||
{
|
||||
string errMsg = SessionStateStrings.GetContent_TailNotSupported;
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "TailNotSupported", ErrorCategory.InvalidOperation, Tail);
|
||||
ErrorRecord error = new(new InvalidOperationException(errMsg), "TailNotSupported", ErrorCategory.InvalidOperation, Tail);
|
||||
WriteError(error);
|
||||
continue;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Exception e)
|
||||
{
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentReadError",
|
||||
SessionStateStrings.ProviderContentReadError,
|
||||
holder.PathInfo.Provider,
|
||||
@@ -218,7 +218,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Exception e) // Catch-all OK. 3rd party callout
|
||||
{
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentReadError",
|
||||
SessionStateStrings.ProviderContentReadError,
|
||||
holder.PathInfo.Provider,
|
||||
@@ -294,7 +294,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Exception e)
|
||||
{
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentReadError",
|
||||
SessionStateStrings.ProviderContentReadError,
|
||||
holder.PathInfo.Provider,
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private ManagementObjectSearcher _searchProcess;
|
||||
|
||||
private bool _inputContainsWildcard = false;
|
||||
private readonly ConnectionOptions _connectionOptions = new ConnectionOptions();
|
||||
private readonly ConnectionOptions _connectionOptions = new();
|
||||
|
||||
/// <summary>
|
||||
/// Sets connection options.
|
||||
@@ -87,8 +87,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
foreach (string computer in ComputerName)
|
||||
{
|
||||
bool foundRecord = false;
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
ManagementScope scope = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), _connectionOptions);
|
||||
StringBuilder queryString = new();
|
||||
ManagementScope scope = new(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), _connectionOptions);
|
||||
scope.Connect();
|
||||
if (Id != null)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
try
|
||||
{
|
||||
SecurityIdentifier secObj = new SecurityIdentifier(installed);
|
||||
SecurityIdentifier secObj = new(installed);
|
||||
obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));
|
||||
}
|
||||
catch (IdentityNotMappedException)
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
CmdletProviderContext coreCommandContext = new CmdletProviderContext(this);
|
||||
CmdletProviderContext coreCommandContext = new(this);
|
||||
|
||||
coreCommandContext.Force = Force;
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
internal Collection<CmdletProviderContext> stopContextCollection =
|
||||
new Collection<CmdletProviderContext>();
|
||||
new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the filter property.
|
||||
@@ -301,7 +301,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
CmdletProviderContext coreCommandContext = new CmdletProviderContext(this, Credential);
|
||||
CmdletProviderContext coreCommandContext = new(this, Credential);
|
||||
coreCommandContext.Force = Force;
|
||||
|
||||
Collection<string> includeFilter =
|
||||
@@ -447,7 +447,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (DriveNotFoundException e)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
e,
|
||||
"GetLocationNoMatchingDrive",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -458,7 +458,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ProviderNotFoundException e)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
e,
|
||||
"GetLocationNoMatchingProvider",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -469,7 +469,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ArgumentException argException)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
argException,
|
||||
"GetLocationNoMatchingDrive",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -523,7 +523,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ProviderNotFoundException e)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
e,
|
||||
"GetLocationNoMatchingProvider",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -1237,7 +1237,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// -Persist switch parameter is supported only for FileSystem provider.
|
||||
if (Persist && !provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new NotSupportedException(FileSystemProviderStrings.PersistNotSupported), "DriveRootNotNetworkPath", ErrorCategory.InvalidArgument, this);
|
||||
ErrorRecord er = new(new NotSupportedException(FileSystemProviderStrings.PersistNotSupported), "DriveRootNotNetworkPath", ErrorCategory.InvalidArgument, this);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
@@ -1249,7 +1249,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Create the new drive
|
||||
PSDriveInfo newDrive =
|
||||
new PSDriveInfo(
|
||||
new(
|
||||
Name,
|
||||
provider,
|
||||
Root,
|
||||
@@ -1368,7 +1368,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
string[] providerNames,
|
||||
string scope)
|
||||
{
|
||||
List<PSDriveInfo> results = new List<PSDriveInfo>();
|
||||
List<PSDriveInfo> results = new();
|
||||
|
||||
if (providerNames == null || providerNames.Length == 0)
|
||||
{
|
||||
@@ -1637,7 +1637,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (verifyMatch && !foundMatch)
|
||||
{
|
||||
DriveNotFoundException e = new DriveNotFoundException(
|
||||
DriveNotFoundException e = new(
|
||||
driveName,
|
||||
"DriveNotFound",
|
||||
SessionStateStrings.DriveNotFound);
|
||||
@@ -1776,7 +1776,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!WildcardPattern.ContainsWildcardCharacters(driveName))
|
||||
{
|
||||
DriveNotFoundException driveNotFound =
|
||||
new DriveNotFoundException(
|
||||
new(
|
||||
driveName,
|
||||
"DriveNotFound",
|
||||
SessionStateStrings.DriveNotFound);
|
||||
@@ -1793,7 +1793,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (DriveNotFoundException driveNotFound)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
driveNotFound,
|
||||
"GetLocationNoMatchingDrive",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -1803,7 +1803,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ProviderNotFoundException providerNotFound)
|
||||
{
|
||||
ErrorRecord errorRecord =
|
||||
new ErrorRecord(
|
||||
new(
|
||||
providerNotFound,
|
||||
"GetLocationNoMatchingDrive",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
@@ -2539,7 +2539,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (SuppressWildcardExpansion == true && resolvedPSPaths.Count == 0)
|
||||
{
|
||||
ItemNotFoundException pathNotFound =
|
||||
new ItemNotFoundException(
|
||||
new(
|
||||
path,
|
||||
"PathNotFound",
|
||||
SessionStateStrings.PathNotFound);
|
||||
@@ -2700,7 +2700,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath);
|
||||
System.IO.DirectoryInfo di = new(providerPath);
|
||||
if (di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0)
|
||||
{
|
||||
shouldRecurse = false;
|
||||
@@ -2941,7 +2941,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private Collection<PathInfo> GetResolvedPaths(string path)
|
||||
{
|
||||
Collection<PathInfo> results = new Collection<PathInfo>();
|
||||
Collection<PathInfo> results = new();
|
||||
try
|
||||
{
|
||||
results = SessionState.Path.GetResolvedPSPathFromPSPath(path, CmdletProviderContext);
|
||||
|
||||
+2
-2
@@ -184,7 +184,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
StringCollection pathsToParse = new StringCollection();
|
||||
StringCollection pathsToParse = new();
|
||||
|
||||
if (Resolve)
|
||||
{
|
||||
@@ -305,7 +305,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (separatorIndex < 0)
|
||||
{
|
||||
FormatException e =
|
||||
new FormatException(
|
||||
new(
|
||||
StringUtil.Format(NavigationResources.ParsePathFormatError, pathsToParse[index]));
|
||||
WriteError(
|
||||
new ErrorRecord(
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// We use a Dictionary to optimize the check whether the object
|
||||
// is already in the list.
|
||||
private List<Process> _matchingProcesses = new List<Process>();
|
||||
private readonly Dictionary<int, Process> _keys = new Dictionary<int, Process>();
|
||||
private List<Process> _matchingProcesses = new();
|
||||
private readonly Dictionary<int, Process> _keys = new();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the list of all processes matching the Name, Id
|
||||
@@ -280,7 +280,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (_allProcesses == null)
|
||||
{
|
||||
List<Process> processes = new List<Process>();
|
||||
List<Process> processes = new();
|
||||
processes.AddRange(Process.GetProcesses());
|
||||
_allProcesses = processes.ToArray();
|
||||
}
|
||||
@@ -358,7 +358,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
processId,
|
||||
(innerException == null) ? string.Empty : innerException.Message);
|
||||
ProcessCommandException exception =
|
||||
new ProcessCommandException(message, innerException);
|
||||
new(message, innerException);
|
||||
exception.ProcessName = processName;
|
||||
|
||||
WriteError(new ErrorRecord(
|
||||
@@ -723,7 +723,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
string userName = RetrieveProcessUserName(process);
|
||||
|
||||
PSObject processAsPsobj = PSObject.AsPSObject(process);
|
||||
PSNoteProperty noteProperty = new PSNoteProperty("UserName", userName);
|
||||
PSNoteProperty noteProperty = new("UserName", userName);
|
||||
|
||||
processAsPsobj.Properties.Add(noteProperty, true);
|
||||
processAsPsobj.TypeNames.Insert(0, TypeNameForProcessWithUserName);
|
||||
@@ -952,7 +952,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#region Overrides
|
||||
|
||||
private readonly List<Process> _processList = new List<Process>();
|
||||
private readonly List<Process> _processList = new();
|
||||
|
||||
// Wait handle which is used by thread to sleep.
|
||||
private ManualResetEvent _waitHandle;
|
||||
@@ -1029,7 +1029,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!process.HasExited)
|
||||
{
|
||||
string message = StringUtil.Format(ProcessResources.ProcessNotTerminated, new object[] { process.ProcessName, process.Id });
|
||||
ErrorRecord errorRecord = new ErrorRecord(new TimeoutException(message), "ProcessNotTerminated", ErrorCategory.CloseError, process);
|
||||
ErrorRecord errorRecord = new(new TimeoutException(message), "ProcessNotTerminated", ErrorCategory.CloseError, process);
|
||||
WriteError(errorRecord);
|
||||
}
|
||||
}
|
||||
@@ -1822,7 +1822,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_nonewwindow && _windowstyleSpecified)
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.ContradictParametersSpecified, "-NoNewWindow", "-WindowStyle");
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1840,12 +1840,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new NotSupportedException(message), "NotSupportedException", ErrorCategory.NotImplemented, null);
|
||||
ErrorRecord er = new(new NotSupportedException(message), "NotSupportedException", ErrorCategory.NotImplemented, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
ProcessStartInfo startInfo = new();
|
||||
// Use ShellExecute by default if we are running on full windows SKUs
|
||||
startInfo.UseShellExecute = Platform.IsWindowsDesktop;
|
||||
|
||||
@@ -1883,7 +1883,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!Directory.Exists(WorkingDirectory))
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.InvalidInput, "WorkingDirectory");
|
||||
ErrorRecord er = new ErrorRecord(new DirectoryNotFoundException(message), "DirectoryNotFoundException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new DirectoryNotFoundException(message), "DirectoryNotFoundException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1942,7 +1942,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!File.Exists(_redirectstandardinput))
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.InvalidInput, "RedirectStandardInput '" + this.RedirectStandardInput + "'");
|
||||
ErrorRecord er = new ErrorRecord(new FileNotFoundException(message), "FileNotFoundException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new FileNotFoundException(message), "FileNotFoundException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1956,7 +1956,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_redirectstandardinput.Equals(_redirectstandardoutput, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.DuplicateEntry, "RedirectStandardInput", "RedirectStandardOutput");
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1970,7 +1970,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_redirectstandardinput.Equals(_redirectstandarderror, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.DuplicateEntry, "RedirectStandardInput", "RedirectStandardError");
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1984,7 +1984,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_redirectstandardoutput.Equals(_redirectstandarderror, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.DuplicateEntry, "RedirectStandardOutput", "RedirectStandardError");
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -2011,7 +2011,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
else
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.CannotStarttheProcess);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
}
|
||||
@@ -2028,7 +2028,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
_waithandle = new ManualResetEvent(false);
|
||||
|
||||
// Create and start the job object
|
||||
ProcessCollection jobObject = new ProcessCollection();
|
||||
ProcessCollection jobObject = new();
|
||||
if (jobObject.AssignProcessToJobObject(process))
|
||||
{
|
||||
// Wait for the job object to finish
|
||||
@@ -2047,7 +2047,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
else
|
||||
{
|
||||
message = StringUtil.Format(ProcessResources.CannotStarttheProcess);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
}
|
||||
@@ -2269,7 +2269,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private SafeFileHandle GetSafeFileHandleForRedirection(string RedirectionPath, uint dwCreationDisposition)
|
||||
{
|
||||
System.IntPtr hFileHandle = System.IntPtr.Zero;
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpSecurityAttributes = new ProcessNativeMethods.SECURITY_ATTRIBUTES();
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpSecurityAttributes = new();
|
||||
|
||||
hFileHandle = ProcessNativeMethods.CreateFileW(RedirectionPath,
|
||||
ProcessNativeMethods.GENERIC_READ | ProcessNativeMethods.GENERIC_WRITE,
|
||||
@@ -2281,19 +2281,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hFileHandle == System.IntPtr.Zero)
|
||||
{
|
||||
int error = Marshal.GetLastWin32Error();
|
||||
Win32Exception win32ex = new Win32Exception(error);
|
||||
Win32Exception win32ex = new(error);
|
||||
string message = StringUtil.Format(ProcessResources.InvalidStartProcess, win32ex.Message);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
SafeFileHandle sf = new SafeFileHandle(hFileHandle, true);
|
||||
SafeFileHandle sf = new(hFileHandle, true);
|
||||
return sf;
|
||||
}
|
||||
|
||||
private static StringBuilder BuildCommandLine(string executableFileName, string arguments)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilder builder = new();
|
||||
string str = executableFileName.Trim();
|
||||
bool flag = str.StartsWith('"') && str.EndsWith('"');
|
||||
if (!flag)
|
||||
@@ -2324,7 +2324,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
string[] strArray2 = new string[sd.Count];
|
||||
sd.Values.CopyTo(strArray2, 0);
|
||||
Array.Sort(array, strArray2, StringComparer.OrdinalIgnoreCase);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilder builder = new();
|
||||
for (int i = 0; i < sd.Count; i++)
|
||||
{
|
||||
builder.Append(array[i]);
|
||||
@@ -2430,10 +2430,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
private Process StartWithCreateProcess(ProcessStartInfo startinfo)
|
||||
{
|
||||
ProcessNativeMethods.STARTUPINFO lpStartupInfo = new ProcessNativeMethods.STARTUPINFO();
|
||||
SafeNativeMethods.PROCESS_INFORMATION lpProcessInformation = new SafeNativeMethods.PROCESS_INFORMATION();
|
||||
ProcessNativeMethods.STARTUPINFO lpStartupInfo = new();
|
||||
SafeNativeMethods.PROCESS_INFORMATION lpProcessInformation = new();
|
||||
int error = 0;
|
||||
GCHandle pinnedEnvironmentBlock = new GCHandle();
|
||||
GCHandle pinnedEnvironmentBlock = new();
|
||||
IntPtr AddressOfEnvironmentBlock = IntPtr.Zero;
|
||||
string message = string.Empty;
|
||||
|
||||
@@ -2497,7 +2497,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
Win32Exception win32ex = new Win32Exception(error);
|
||||
Win32Exception win32ex = new(error);
|
||||
message = StringUtil.Format(ProcessResources.InvalidStartProcess, win32ex.Message);
|
||||
}
|
||||
|
||||
@@ -2525,23 +2525,23 @@ namespace Microsoft.PowerShell.Commands
|
||||
IntPtr token = WindowsIdentity.GetCurrent().Token;
|
||||
if (!ProcessNativeMethods.CreateEnvironmentBlock(out AddressOfEnvironmentBlock, token, false))
|
||||
{
|
||||
Win32Exception win32ex = new Win32Exception(error);
|
||||
Win32Exception win32ex = new(error);
|
||||
message = StringUtil.Format(ProcessResources.InvalidStartProcess, win32ex.Message);
|
||||
var errorRecord = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpProcessAttributes = new ProcessNativeMethods.SECURITY_ATTRIBUTES();
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpThreadAttributes = new ProcessNativeMethods.SECURITY_ATTRIBUTES();
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpProcessAttributes = new();
|
||||
ProcessNativeMethods.SECURITY_ATTRIBUTES lpThreadAttributes = new();
|
||||
flag = ProcessNativeMethods.CreateProcess(null, cmdLine, lpProcessAttributes, lpThreadAttributes, true, creationFlags, AddressOfEnvironmentBlock, startinfo.WorkingDirectory, lpStartupInfo, lpProcessInformation);
|
||||
if (!flag)
|
||||
{
|
||||
error = Marshal.GetLastWin32Error();
|
||||
|
||||
Win32Exception win32ex = new Win32Exception(error);
|
||||
Win32Exception win32ex = new(error);
|
||||
message = StringUtil.Format(ProcessResources.InvalidStartProcess, win32ex.Message);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
@@ -2583,7 +2583,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Win32Exception ex)
|
||||
{
|
||||
string message = StringUtil.Format(ProcessResources.InvalidStartProcess, ex.Message);
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
@@ -2634,7 +2634,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
ManualResetEvent emptyJobAutoEvent = (ManualResetEvent)stateInfo;
|
||||
int dwSize = 0;
|
||||
const int JOB_OBJECT_BASIC_PROCESS_ID_LIST = 3;
|
||||
JOBOBJECT_BASIC_PROCESS_ID_LIST JobList = new JOBOBJECT_BASIC_PROCESS_ID_LIST();
|
||||
JOBOBJECT_BASIC_PROCESS_ID_LIST JobList = new();
|
||||
|
||||
dwSize = Marshal.SizeOf(JobList);
|
||||
if (NativeMethods.QueryInformationJobObject(_jobObjectHandle,
|
||||
@@ -2659,7 +2659,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal void WaitOne(ManualResetEvent waitHandleToUse)
|
||||
{
|
||||
TimerCallback jobObjectStatusCb = this.CheckJobStatus;
|
||||
using (Timer stateTimer = new Timer(jobObjectStatusCb, waitHandleToUse, 0, 1000))
|
||||
using (Timer stateTimer = new(jobObjectStatusCb, waitHandleToUse, 0, 1000))
|
||||
{
|
||||
waitHandleToUse.WaitOne();
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!status)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
bool accessDenied = exception.NativeErrorCode == NativeMethods.ERROR_ACCESS_DENIED;
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
@@ -380,7 +380,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </remarks>
|
||||
private List<ServiceController> MatchingServicesByServiceName()
|
||||
{
|
||||
List<ServiceController> matchingServices = new List<ServiceController>();
|
||||
List<ServiceController> matchingServices = new();
|
||||
|
||||
if (serviceNames == null)
|
||||
{
|
||||
@@ -443,7 +443,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
private List<ServiceController> MatchingServicesByDisplayName()
|
||||
{
|
||||
List<ServiceController> matchingServices = new List<ServiceController>();
|
||||
List<ServiceController> matchingServices = new();
|
||||
if (DisplayName == null)
|
||||
{
|
||||
Diagnostics.Assert(false, "null DisplayName");
|
||||
@@ -486,7 +486,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
private List<ServiceController> MatchingServicesByInput()
|
||||
{
|
||||
List<ServiceController> matchingServices = new List<ServiceController>();
|
||||
List<ServiceController> matchingServices = new();
|
||||
if (InputObject == null)
|
||||
{
|
||||
Diagnostics.Assert(false, "null InputObject");
|
||||
@@ -669,7 +669,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hScManager == IntPtr.Zero)
|
||||
{
|
||||
lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -686,7 +686,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hService == IntPtr.Zero)
|
||||
{
|
||||
lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -695,13 +695,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
ErrorCategory.PermissionDenied);
|
||||
}
|
||||
|
||||
NativeMethods.SERVICE_DESCRIPTIONW description = new NativeMethods.SERVICE_DESCRIPTIONW();
|
||||
NativeMethods.SERVICE_DESCRIPTIONW description = new();
|
||||
bool querySuccessful = NativeMethods.QueryServiceConfig2<NativeMethods.SERVICE_DESCRIPTIONW>(hService, NativeMethods.SERVICE_CONFIG_DESCRIPTION, out description);
|
||||
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO autostartInfo = new NativeMethods.SERVICE_DELAYED_AUTO_START_INFO();
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO autostartInfo = new();
|
||||
querySuccessful = querySuccessful && NativeMethods.QueryServiceConfig2<NativeMethods.SERVICE_DELAYED_AUTO_START_INFO>(hService, NativeMethods.SERVICE_CONFIG_DELAYED_AUTO_START_INFO, out autostartInfo);
|
||||
|
||||
NativeMethods.QUERY_SERVICE_CONFIG serviceInfo = new NativeMethods.QUERY_SERVICE_CONFIG();
|
||||
NativeMethods.QUERY_SERVICE_CONFIG serviceInfo = new();
|
||||
querySuccessful = querySuccessful && NativeMethods.QueryServiceConfig(hService, out serviceInfo);
|
||||
|
||||
if (!querySuccessful)
|
||||
@@ -715,7 +715,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
);
|
||||
}
|
||||
|
||||
PSProperty noteProperty = new PSProperty("UserName", serviceInfo.lpServiceStartName);
|
||||
PSProperty noteProperty = new("UserName", serviceInfo.lpServiceStartName);
|
||||
serviceAsPSObj.Properties.Add(noteProperty, true);
|
||||
serviceAsPSObj.TypeNames.Insert(0, "System.Service.ServiceController#UserName");
|
||||
|
||||
@@ -960,7 +960,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Ignore ServiceController.CanStop. CanStop will be set false
|
||||
// if the service is not running, but this is not an error.
|
||||
|
||||
List<ServiceController> stoppedServices = new List<ServiceController>();
|
||||
List<ServiceController> stoppedServices = new();
|
||||
ServiceController[] dependentServices = null;
|
||||
|
||||
try
|
||||
@@ -1705,14 +1705,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
// cannot use WriteNonterminatingError as service is null
|
||||
ErrorRecord er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.ObjectNotFound, Name);
|
||||
ErrorRecord er = new(ex, "ArgumentException", ErrorCategory.ObjectNotFound, Name);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
// cannot use WriteNonterminatingError as service is null
|
||||
ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.ObjectNotFound, Name);
|
||||
ErrorRecord er = new(ex, "InvalidOperationException", ErrorCategory.ObjectNotFound, Name);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -1740,7 +1740,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hScManager == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -1759,7 +1759,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hService == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -1805,7 +1805,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -1816,7 +1816,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
NativeMethods.SERVICE_DESCRIPTIONW sd = new NativeMethods.SERVICE_DESCRIPTIONW();
|
||||
NativeMethods.SERVICE_DESCRIPTIONW sd = new();
|
||||
sd.lpDescription = Description;
|
||||
int size = Marshal.SizeOf(sd);
|
||||
IntPtr buffer = Marshal.AllocCoTaskMem(size);
|
||||
@@ -1830,7 +1830,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!status)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -1840,7 +1840,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Set the delayed auto start
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO ds = new NativeMethods.SERVICE_DELAYED_AUTO_START_INFO();
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO ds = new();
|
||||
ds.fDelayedAutostart = StartupType == ServiceStartupType.AutomaticDelayedStart;
|
||||
size = Marshal.SizeOf(ds);
|
||||
delayedAutoStartInfoBuffer = Marshal.AllocCoTaskMem(size);
|
||||
@@ -1854,7 +1854,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!status)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -1914,7 +1914,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (PassThru.IsPresent)
|
||||
{
|
||||
// To display the service, refreshing the service would not show the display name after updating
|
||||
ServiceController displayservice = new ServiceController(Name);
|
||||
ServiceController displayservice = new(Name);
|
||||
WriteObject(displayservice);
|
||||
}
|
||||
}
|
||||
@@ -1931,7 +1931,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -1947,7 +1947,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -2136,7 +2136,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hScManager == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2213,7 +2213,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hService == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2226,7 +2226,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Set the service description
|
||||
NativeMethods.SERVICE_DESCRIPTIONW sd = new NativeMethods.SERVICE_DESCRIPTIONW();
|
||||
NativeMethods.SERVICE_DESCRIPTIONW sd = new();
|
||||
sd.lpDescription = Description;
|
||||
int size = Marshal.SizeOf(sd);
|
||||
IntPtr buffer = Marshal.AllocCoTaskMem(size);
|
||||
@@ -2240,7 +2240,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2254,7 +2254,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Set the delayed auto start
|
||||
if (StartupType == ServiceStartupType.AutomaticDelayedStart)
|
||||
{
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO ds = new NativeMethods.SERVICE_DELAYED_AUTO_START_INFO();
|
||||
NativeMethods.SERVICE_DELAYED_AUTO_START_INFO ds = new();
|
||||
ds.fDelayedAutostart = true;
|
||||
size = Marshal.SizeOf(ds);
|
||||
delayedAutoStartInfoBuffer = Marshal.AllocCoTaskMem(size);
|
||||
@@ -2268,7 +2268,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2308,7 +2308,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2326,7 +2326,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!succeeded)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
Name,
|
||||
DisplayName,
|
||||
@@ -2402,14 +2402,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
// Cannot use WriteNonterminatingError as service is null
|
||||
ErrorRecord er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.ObjectNotFound, Name);
|
||||
ErrorRecord er = new(ex, "ArgumentException", ErrorCategory.ObjectNotFound, Name);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
// Cannot use WriteNonterminatingError as service is null
|
||||
ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.ObjectNotFound, Name);
|
||||
ErrorRecord er = new(ex, "InvalidOperationException", ErrorCategory.ObjectNotFound, Name);
|
||||
WriteError(er);
|
||||
return;
|
||||
}
|
||||
@@ -2435,7 +2435,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hScManager == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteObject(exception);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
@@ -2454,7 +2454,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (hService == IntPtr.Zero)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
@@ -2469,7 +2469,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!status)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
Win32Exception exception = new Win32Exception(lastError);
|
||||
Win32Exception exception = new(lastError);
|
||||
WriteNonTerminatingError(
|
||||
service,
|
||||
exception,
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("scb")]
|
||||
public class SetClipboardCommand : PSCmdlet
|
||||
{
|
||||
private readonly List<string> _contentList = new List<string>();
|
||||
private readonly List<string> _contentList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets clipboard content.
|
||||
@@ -84,7 +84,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder content = new StringBuilder();
|
||||
StringBuilder content = new();
|
||||
if (append)
|
||||
{
|
||||
content.AppendLine(Clipboard.GetText());
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
throw PSTraceSource.NewArgumentNullException(nameof(paths));
|
||||
}
|
||||
|
||||
CmdletProviderContext context = new CmdletProviderContext(GetCurrentContext());
|
||||
CmdletProviderContext context = new(GetCurrentContext());
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
|
||||
+13
-13
@@ -57,7 +57,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private static byte[]? s_DefaultSendBuffer;
|
||||
|
||||
private readonly CancellationTokenSource _dnsLookupCancel = new CancellationTokenSource();
|
||||
private readonly CancellationTokenSource _dnsLookupCancel = new();
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
TcpClient client = new TcpClient();
|
||||
TcpClient client = new();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -350,11 +350,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
int currentHop = 1;
|
||||
PingOptions pingOptions = new PingOptions(currentHop, DontFragment.IsPresent);
|
||||
PingOptions pingOptions = new(currentHop, DontFragment.IsPresent);
|
||||
PingReply reply;
|
||||
PingReply discoveryReply;
|
||||
int timeout = TimeoutSeconds * 1000;
|
||||
Stopwatch timer = new Stopwatch();
|
||||
Stopwatch timer = new();
|
||||
|
||||
IPAddress hopAddress;
|
||||
do
|
||||
@@ -436,7 +436,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
resolvedTargetName,
|
||||
ex.Message);
|
||||
Exception pingException = new PingException(message, ex.InnerException);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -499,7 +499,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
try
|
||||
{
|
||||
PingOptions pingOptions = new PingOptions(MaxHops, true);
|
||||
PingOptions pingOptions = new(MaxHops, true);
|
||||
int retry = 1;
|
||||
|
||||
while (LowMTUSize < (HighMTUSize - 1))
|
||||
@@ -535,7 +535,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
targetAddress,
|
||||
reply.Status.ToString());
|
||||
Exception pingException = new PingException(message);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -560,7 +560,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
string message = StringUtil.Format(TestConnectionResources.NoPingResult, targetAddress, ex.Message);
|
||||
Exception pingException = new PingException(message, ex.InnerException);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -603,7 +603,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
byte[] buffer = GetSendBuffer(BufferSize);
|
||||
|
||||
PingReply reply;
|
||||
PingOptions pingOptions = new PingOptions(MaxHops, DontFragment.IsPresent);
|
||||
PingOptions pingOptions = new(MaxHops, DontFragment.IsPresent);
|
||||
int timeout = TimeoutSeconds * 1000;
|
||||
int delay = Delay * 1000;
|
||||
|
||||
@@ -617,7 +617,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
string message = StringUtil.Format(TestConnectionResources.NoPingResult, resolvedTargetName, ex.Message);
|
||||
Exception pingException = new PingException(message, ex.InnerException);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -678,7 +678,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
resolvedTargetName,
|
||||
TestConnectionResources.TargetAddressAbsent);
|
||||
Exception pingException = new PingException(message, null);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -722,7 +722,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
resolvedTargetName,
|
||||
TestConnectionResources.CannotResolveTargetName);
|
||||
Exception pingException = new PingException(message, ex);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
@@ -744,7 +744,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
resolvedTargetName,
|
||||
TestConnectionResources.TargetAddressAbsent);
|
||||
Exception pingException = new PingException(message, null);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
pingException,
|
||||
TestConnectionExceptionId,
|
||||
ErrorCategory.ResourceUnavailable,
|
||||
|
||||
+6
-6
@@ -254,14 +254,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
try
|
||||
{
|
||||
// construct and populate a new DYNAMIC_TIME_ZONE_INFORMATION structure
|
||||
NativeMethods.DYNAMIC_TIME_ZONE_INFORMATION dtzi = new NativeMethods.DYNAMIC_TIME_ZONE_INFORMATION();
|
||||
NativeMethods.DYNAMIC_TIME_ZONE_INFORMATION dtzi = new();
|
||||
dtzi.Bias -= (int)InputObject.BaseUtcOffset.TotalMinutes;
|
||||
dtzi.StandardName = InputObject.StandardName;
|
||||
dtzi.DaylightName = InputObject.DaylightName;
|
||||
dtzi.TimeZoneKeyName = InputObject.Id;
|
||||
|
||||
// Request time zone transition information for the current year
|
||||
NativeMethods.TIME_ZONE_INFORMATION tzi = new NativeMethods.TIME_ZONE_INFORMATION();
|
||||
NativeMethods.TIME_ZONE_INFORMATION tzi = new();
|
||||
if (!NativeMethods.GetTimeZoneInformationForYear((ushort)DateTime.Now.Year, ref dtzi, ref tzi))
|
||||
{
|
||||
ThrowWin32Error();
|
||||
@@ -343,7 +343,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
try
|
||||
{
|
||||
// setup the privileges being checked
|
||||
NativeMethods.PRIVILEGE_SET ps = new NativeMethods.PRIVILEGE_SET()
|
||||
NativeMethods.PRIVILEGE_SET ps = new()
|
||||
{
|
||||
PrivilegeCount = 1,
|
||||
Control = 1,
|
||||
@@ -390,7 +390,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
try
|
||||
{
|
||||
// setup the privileges being requested
|
||||
NativeMethods.TOKEN_PRIVILEGES tp = new NativeMethods.TOKEN_PRIVILEGES()
|
||||
NativeMethods.TOKEN_PRIVILEGES tp = new()
|
||||
{
|
||||
PrivilegeCount = 1,
|
||||
Luid = 0,
|
||||
@@ -779,8 +779,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>A TimeZoneInfo object array containing information about the specified system time zones.</returns>
|
||||
internal static TimeZoneInfo[] LookupSystemTimeZoneInfoByName(string name)
|
||||
{
|
||||
WildcardPattern namePattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);
|
||||
List<TimeZoneInfo> tzi = new List<TimeZoneInfo>();
|
||||
WildcardPattern namePattern = new(name, WildcardOptions.IgnoreCase);
|
||||
List<TimeZoneInfo> tzi = new();
|
||||
|
||||
// get the available system time zones
|
||||
ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones();
|
||||
|
||||
+3
-3
@@ -143,7 +143,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (Exception e) // Catch-all OK. 3rd party callout
|
||||
{
|
||||
ProviderInvocationException providerException =
|
||||
new ProviderInvocationException(
|
||||
new(
|
||||
"ProviderContentWriteError",
|
||||
SessionStateStrings.ProviderContentWriteError,
|
||||
holder.PathInfo.Provider,
|
||||
@@ -258,7 +258,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Create the results array
|
||||
|
||||
List<ContentHolder> results = new List<ContentHolder>();
|
||||
List<ContentHolder> results = new();
|
||||
|
||||
foreach (PathInfo pathInfo in pathInfos)
|
||||
{
|
||||
@@ -311,7 +311,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (writers.Count == 1 && writers[0] != null)
|
||||
{
|
||||
ContentHolder holder =
|
||||
new ContentHolder(pathInfo, null, writers[0]);
|
||||
new(pathInfo, null, writers[0]);
|
||||
|
||||
results.Add(holder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user