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 @@ -90,7 +90,7 @@ internal static CimJobException CreateFromCimException(
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;
}
Expand All @@ -111,7 +111,7 @@ internal static CimJobException CreateFromAnyException(
}

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)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ internal static CimJobException CreateWithFullControl(
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;
}
Expand All @@ -156,7 +156,7 @@ internal static CimJobException CreateWithoutJobContext(
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;
}
Expand All @@ -170,7 +170,7 @@ internal static CimJobException CreateFromMethodErrorCode(string jobDescription,

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;
Expand All @@ -197,15 +197,15 @@ private static string BuildErrorMessage(string jobDescription, CimJobContext job

private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
{
ErrorRecord coreErrorRecord = new ErrorRecord(
ErrorRecord coreErrorRecord = new(
exception: exception,
errorId: errorId,
errorCategory: errorCategory,
targetObject: jobContext?.TargetObject);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class TerminatingErrorTracker
#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)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ private TerminatingErrorTracker(int numberOfSessions)

#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)
{
Expand Down Expand Up @@ -166,7 +166,7 @@ internal Exception GetExceptionIfBrokenSession(

#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)
{
Expand Down Expand Up @@ -196,8 +196,8 @@ internal bool IsSessionTerminated(CimSession session)

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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal CimChildJobBase(CimJobContext jobContext)
_jobSpecificCustomOptions = new Lazy<CimCustomOptionsDictionary>(this.CalculateJobSpecificCustomOptions);
}

private readonly CimSensitiveValueConverter _cimSensitiveValueConverter = new CimSensitiveValueConverter();
private readonly CimSensitiveValueConverter _cimSensitiveValueConverter = new();

internal CimSensitiveValueConverter CimSensitiveValueConverter { get { return _cimSensitiveValueConverter; } }

Expand Down Expand Up @@ -158,7 +158,7 @@ public virtual void OnCompleted()
});
}

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;
Expand Down Expand Up @@ -543,7 +543,7 @@ private CimCustomOptionsDictionary GetJobSpecificCustomOptions()

#region Controlling job state

private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private readonly CancellationTokenSource _cancellationTokenSource = new();

/// <summary>
/// Stops this job.
Expand Down Expand Up @@ -578,7 +578,7 @@ public override void StopJob()
_cancellationTokenSource.Cancel();
}

private readonly object _jobStateLock = new object();
private readonly object _jobStateLock = new();
private bool _jobHadErrors;
private bool _jobWasStarted;
private bool _jobWasStopped;
Expand Down Expand Up @@ -730,7 +730,7 @@ internal void SetCompletedJobState(JobState state, Exception reason)

#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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void WarnAboutUnsupportedActionPreferences(
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);
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public bool ShowComputerName
}
}

private readonly Lazy<CimSession> _defaultCimSession = new Lazy<CimSession>(CreateDefaultCimSession);
private readonly Lazy<CimSession> _defaultCimSession = new(CreateDefaultCimSession);

private static CimSession CreateDefaultCimSession()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void Dispose(bool disposing)
}
}

private readonly List<IDisposable> _trackedDisposables = new List<IDisposable>();
private readonly List<IDisposable> _trackedDisposables = new();

/// <summary>
/// Releases resources associated with this object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -42,7 +42,7 @@ internal static CimCustomOptionsDictionary Create(IEnumerable<KeyValuePair<strin
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class CimQuery : QueryBuilder, ISessionBoundQueryBuilder<CimSession>
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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker t
cimSession.ComputerName,
nameOfUnsupportedSwitch);
Exception exception = new NotSupportedException(errorMessage);
ErrorRecord errorRecord = new ErrorRecord(
ErrorRecord errorRecord = new(
exception,
"NoExtendedSemanticsSupportInRemoteDcomProtocol",
ErrorCategory.NotImplemented,
Expand Down Expand Up @@ -339,7 +339,7 @@ internal override StartableJob CreateStaticMethodInvocationJob(CimSession sessio

#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)
{
Expand Down Expand Up @@ -395,10 +395,10 @@ object IDynamicParameters.GetDynamicParameters()

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public virtual IEnumerable<NotFoundError> GetNotFoundErrors_IfThisIsTheOnlyFilte

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

Expand Down Expand Up @@ -624,8 +624,8 @@ private static bool ActualValueLessThanOrEqualToExpectedValue(string propertyNam
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal override void SeekContentPosition(List<ContentHolder> contentHolders)
catch (Exception e) // Catch-all OK, 3rd party callout
{
ProviderInvocationException providerException =
new ProviderInvocationException(
new(
"ProviderSeekError",
SessionStateStrings.ProviderSeekError,
holder.PathInfo.Provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal static string WqlQueryAll(string from)
{
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)))
{
Expand Down Expand Up @@ -148,7 +148,7 @@ internal static string WqlQueryAll(string from)

foreach (var instance in instances)
{
T objT = new T();
T objT = new();

using (instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public string Name
/// </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)
Expand Down Expand Up @@ -124,7 +124,7 @@ protected override void ProcessRecord()
CmdletProviderContext currentContext = CmdletProviderContext;
currentContext.PassThru = PassThru;

Collection<string> propertyCollection = new Collection<string>();
Collection<string> propertyCollection = new();
propertyCollection.Add(_property);

foreach (string path in Path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void EmptyRecycleBin(string drivePath)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private static string StartProcess(
string args,
string stdin = "")
{
ProcessStartInfo startInfo = new ProcessStartInfo();
ProcessStartInfo startInfo = new();
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
Expand All @@ -30,7 +30,7 @@ private static string StartProcess(
startInfo.Arguments = args;
string stdout;

using (Process process = new Process())
using (Process process = new())
{
process.StartInfo = startInfo;
try
Expand Down
Loading