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 @@ -63,7 +63,7 @@ public static uint FormatMessageFromModule(uint lastError, string moduleName, ou
LANGID = 0; // neutral
}

StringBuilder outStringBuilder = new StringBuilder(1024);
StringBuilder outStringBuilder = new(1024);
uint nChars = FormatMessage(dwFormatFlags,
moduleHandle,
lastError,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public StringCollection Paths
{
get
{
StringCollection retColl = new StringCollection();
StringCollection retColl = new();
foreach (string counterName in this.CounterInstanceMapping.Keys)
{
string path;
Expand Down Expand Up @@ -117,7 +117,7 @@ public StringCollection PathsWithInstances
{
get
{
StringCollection retColl = new StringCollection();
StringCollection retColl = new();
foreach (string counterName in CounterInstanceMapping.Keys)
{
foreach (string instanceName in CounterInstanceMapping[counterName])
Expand Down
40 changes: 20 additions & 20 deletions src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public string[] Counter

private bool _defaultCounters = true;

private readonly List<string> _accumulatedCounters = new List<string>();
private readonly List<string> _accumulatedCounters = new();

//
// SampleInterval parameter.
Expand Down Expand Up @@ -168,7 +168,7 @@ public string[] ComputerName

private PdhHelper _pdhHelper = null;

private readonly EventWaitHandle _cancelEventArrived = new EventWaitHandle(false, EventResetMode.ManualReset);
private readonly EventWaitHandle _cancelEventArrived = new(false, EventResetMode.ManualReset);

// Culture identifier(s)
private const string FrenchCultureId = "fr-FR";
Expand All @@ -180,7 +180,7 @@ public string[] ComputerName
//
// With this dictionary, we can add special mapping if we find other special cases in the future.
private readonly Dictionary<string, List<Tuple<char, char>>> _cultureAndSpecialCharacterMap =
new Dictionary<string, List<Tuple<char, char>>>()
new()
{
{
FrenchCultureId, new List<Tuple<char, char>>()
Expand Down Expand Up @@ -218,7 +218,7 @@ protected override void BeginProcessing()

if (Continuous.IsPresent && _maxSamplesSpecified)
{
Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples")));
Exception exc = new(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples")));
ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null));
}
}
Expand Down Expand Up @@ -305,20 +305,20 @@ private void ProcessListSet()
//
private void ProcessListSetPerMachine(string machine)
{
StringCollection counterSets = new StringCollection();
StringCollection counterSets = new();
uint res = _pdhHelper.EnumObjects(machine, ref counterSets);
if (res != PdhResults.PDH_CSTATUS_VALID_DATA)
{
// add an error message
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoCounterSetsOnComputer"), machine, res);
Exception exc = new Exception(msg);
Exception exc = new(msg);
WriteError(new ErrorRecord(exc, "NoCounterSetsOnComputer", ErrorCategory.InvalidResult, machine));
return;
}

CultureInfo culture = GetCurrentCulture();
List<Tuple<char, char>> characterReplacementList = null;
StringCollection validPaths = new StringCollection();
StringCollection validPaths = new();

_cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);

Expand All @@ -335,7 +335,7 @@ private void ProcessListSetPerMachine(string machine)
}
}

WildcardPattern wildLogPattern = new WildcardPattern(normalizedPattern, WildcardOptions.IgnoreCase);
WildcardPattern wildLogPattern = new(normalizedPattern, WildcardOptions.IgnoreCase);

foreach (string counterSet in counterSets)
{
Expand All @@ -344,14 +344,14 @@ private void ProcessListSetPerMachine(string machine)
continue;
}

StringCollection counterSetCounters = new StringCollection();
StringCollection counterSetInstances = new StringCollection();
StringCollection counterSetCounters = new();
StringCollection counterSetInstances = new();

res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
if (res == PdhResults.PDH_ACCESS_DENIED)
{
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSetEnumAccessDenied"), counterSet);
Exception exc = new Exception(msg);
Exception exc = new(msg);
WriteError(new ErrorRecord(exc, "CounterSetEnumAccessDenied", ErrorCategory.InvalidResult, null));
continue;
}
Expand All @@ -377,7 +377,7 @@ private void ProcessListSetPerMachine(string machine)
instanceArray[0] = "*";
}

Dictionary<string, string[]> counterInstanceMapping = new Dictionary<string, string[]>();
Dictionary<string, string[]> counterInstanceMapping = new();
foreach (string counter in counterSetCounters)
{
counterInstanceMapping.TryAdd(counter, instanceArray);
Expand All @@ -395,15 +395,15 @@ private void ProcessListSetPerMachine(string machine)

string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet);

CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
CounterSet setObj = new(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
WriteObject(setObj);
bMatched = true;
}

if (!bMatched)
{
string msg = _resourceMgr.GetString("NoMatchingCounterSetsFound");
Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg,
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg,
machine ?? "localhost", normalizedPattern));
WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsFound", ErrorCategory.ObjectNotFound, null));
}
Expand Down Expand Up @@ -431,7 +431,7 @@ private void ProcessGetCounter()
_cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);
}

StringCollection allExpandedPaths = new StringCollection();
StringCollection allExpandedPaths = new();
uint res;
foreach (string path in paths)
{
Expand All @@ -442,7 +442,7 @@ private void ProcessGetCounter()
if (res != PdhResults.PDH_CSTATUS_VALID_DATA)
{
string msg = string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterPathTranslationFailed"), res);
Exception exc = new Exception(msg);
Exception exc = new(msg);
WriteError(new ErrorRecord(exc, "CounterPathTranslationFailed", ErrorCategory.InvalidResult, null));

localizedPath = path;
Expand Down Expand Up @@ -470,7 +470,7 @@ private void ProcessGetCounter()
if (!_pdhHelper.IsPathValid(expandedPath))
{
string msg = string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterPathIsInvalid"), localizedPath);
Exception exc = new Exception(msg);
Exception exc = new(msg);
WriteError(new ErrorRecord(exc, "CounterPathIsInvalid", ErrorCategory.InvalidResult, null));

continue;
Expand Down Expand Up @@ -567,7 +567,7 @@ private void ReportPdhError(uint res, bool bTerminate)
msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterApiError"), res);
}

Exception exc = new Exception(msg);
Exception exc = new(msg);
if (bTerminate)
{
ThrowTerminatingError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
Expand All @@ -585,7 +585,7 @@ private void ReportPdhError(uint res, bool bTerminate)
//
private List<string> CombineMachinesAndCounterPaths()
{
List<string> retColl = new List<string>();
List<string> retColl = new();

if (_computerName.Length == 0)
{
Expand Down Expand Up @@ -630,7 +630,7 @@ private void WriteSampleSetObject(PerformanceCounterSampleSet set)
if (sample.Status != 0)
{
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSampleDataInvalid"));
Exception exc = new Exception(msg);
Exception exc = new(msg);
WriteError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
break;
}
Expand Down
Loading