Skip to content

Commit 1de0b64

Browse files
authored
1 parent edb70b1 commit 1de0b64

23 files changed

+110
-110
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ internal UniquePSObjectHelper(PSObject o, int notePropertyCount)
341341

342342
private void ProcessExpressionParameter()
343343
{
344-
TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
344+
TerminatingErrorContext invocationContext = new(this);
345345
ParameterProcessor processor =
346-
new ParameterProcessor(new SelectObjectExpressionParameterDefinition());
346+
new(new SelectObjectExpressionParameterDefinition());
347347
if ((Property != null) && (Property.Length != 0))
348348
{
349349
// Build property list taking into account the wildcards and @{name=;expression=}
@@ -382,18 +382,18 @@ private void ProcessObject(PSObject inputObject)
382382
}
383383

384384
// If property parameter is mentioned
385-
List<PSNoteProperty> matchedProperties = new List<PSNoteProperty>();
385+
List<PSNoteProperty> matchedProperties = new();
386386
foreach (MshParameter p in _propertyMshParameterList)
387387
{
388388
ProcessParameter(p, inputObject, matchedProperties);
389389
}
390390

391391
if (string.IsNullOrEmpty(ExpandProperty))
392392
{
393-
PSObject result = new PSObject();
393+
PSObject result = new();
394394
if (matchedProperties.Count != 0)
395395
{
396-
HashSet<string> propertyNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
396+
HashSet<string> propertyNames = new(StringComparer.OrdinalIgnoreCase);
397397

398398
foreach (PSNoteProperty noteProperty in matchedProperties)
399399
{
@@ -431,7 +431,7 @@ private void ProcessParameter(MshParameter p, PSObject inputObject, List<PSNoteP
431431
string name = p.GetEntry(NameEntryDefinition.NameEntryKey) as string;
432432

433433
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
434-
List<PSPropertyExpressionResult> expressionResults = new List<PSPropertyExpressionResult>();
434+
List<PSPropertyExpressionResult> expressionResults = new();
435435
foreach (PSPropertyExpression resolvedName in ex.ResolveNames(inputObject))
436436
{
437437
if (_exclusionFilter == null || !_exclusionFilter.IsMatch(resolvedName))
@@ -456,7 +456,7 @@ private void ProcessParameter(MshParameter p, PSObject inputObject, List<PSNoteP
456456
else if (!string.IsNullOrEmpty(name) && expressionResults.Count > 1)
457457
{
458458
string errorMsg = SelectObjectStrings.RenamingMultipleResults;
459-
ErrorRecord errorRecord = new ErrorRecord(
459+
ErrorRecord errorRecord = new(
460460
new InvalidOperationException(errorMsg),
461461
"RenamingMultipleResults",
462462
ErrorCategory.InvalidOperation,
@@ -506,7 +506,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,
506506

507507
if (expressionResults.Count == 0)
508508
{
509-
ErrorRecord errorRecord = new ErrorRecord(
509+
ErrorRecord errorRecord = new(
510510
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, ExpandProperty),
511511
"ExpandPropertyNotFound",
512512
ErrorCategory.InvalidArgument,
@@ -516,7 +516,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,
516516

517517
if (expressionResults.Count > 1)
518518
{
519-
ErrorRecord errorRecord = new ErrorRecord(
519+
ErrorRecord errorRecord = new(
520520
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, ExpandProperty),
521521
"MutlipleExpandProperties",
522522
ErrorCategory.InvalidArgument,
@@ -563,7 +563,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,
563563
}
564564
else
565565
{
566-
ErrorRecord errorRecord = new ErrorRecord(
566+
ErrorRecord errorRecord = new(
567567
r.Exception,
568568
"PropertyEvaluationExpand",
569569
ErrorCategory.InvalidResult,
@@ -596,7 +596,7 @@ private void AddNoteProperties(PSObject expandedObject, PSObject inputObject, IE
596596

597597
private void WriteAlreadyExistingPropertyError(string name, object inputObject, string errorId)
598598
{
599-
ErrorRecord errorRecord = new ErrorRecord(
599+
ErrorRecord errorRecord = new(
600600
PSTraceSource.NewArgumentException("Property", SelectObjectStrings.AlreadyExistingProperty, name),
601601
errorId,
602602
ErrorCategory.InvalidOperation,
@@ -624,7 +624,7 @@ private void FilteredWriteObject(PSObject obj, List<PSNoteProperty> addedNotePro
624624
bool isObjUnique = true;
625625
foreach (UniquePSObjectHelper uniqueObj in _uniques)
626626
{
627-
ObjectCommandComparer comparer = new ObjectCommandComparer(true, CultureInfo.CurrentCulture, true);
627+
ObjectCommandComparer comparer = new(true, CultureInfo.CurrentCulture, true);
628628
if ((comparer.Compare(obj.BaseObject, uniqueObj.WrittenObject.BaseObject) == 0) &&
629629
(uniqueObj.NotePropertyCount == addedNoteProperties.Count))
630630
{

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public Encoding Encoding
173173
#region Private variables and methods
174174

175175
// Instantiate a new instance of MailMessage
176-
private readonly MailMessage _mMailMessage = new MailMessage();
176+
private readonly MailMessage _mMailMessage = new();
177177

178178
private SmtpClient _mSmtpClient = null;
179179

@@ -216,7 +216,7 @@ private void AddAddressesToMailMessage(object address, string param)
216216
}
217217
catch (FormatException e)
218218
{
219-
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, null);
219+
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, null);
220220
WriteError(er);
221221
continue;
222222
}
@@ -239,7 +239,7 @@ protected override void BeginProcessing()
239239
}
240240
catch (FormatException e)
241241
{
242-
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, From);
242+
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, From);
243243
ThrowTerminatingError(er);
244244
}
245245

@@ -294,7 +294,7 @@ protected override void BeginProcessing()
294294

295295
if (string.IsNullOrEmpty(SmtpServer))
296296
{
297-
ErrorRecord er = new ErrorRecord(new InvalidOperationException(SendMailMessageStrings.HostNameValue), null, ErrorCategory.InvalidArgument, null);
297+
ErrorRecord er = new(new InvalidOperationException(SendMailMessageStrings.HostNameValue), null, ErrorCategory.InvalidArgument, null);
298298
this.ThrowTerminatingError(er);
299299
}
300300

@@ -344,7 +344,7 @@ protected override void ProcessRecord()
344344
PathUtils.ReportFileOpenFailure(this, filepath, e);
345345
}
346346

347-
Attachment mailAttachment = new Attachment(filepath);
347+
Attachment mailAttachment = new(filepath);
348348
_mMailMessage.Attachments.Add(mailAttachment);
349349
}
350350
}
@@ -362,30 +362,30 @@ protected override void EndProcessing()
362362
}
363363
catch (SmtpFailedRecipientsException ex)
364364
{
365-
ErrorRecord er = new ErrorRecord(ex, "SmtpFailedRecipientsException", ErrorCategory.InvalidOperation, _mSmtpClient);
365+
ErrorRecord er = new(ex, "SmtpFailedRecipientsException", ErrorCategory.InvalidOperation, _mSmtpClient);
366366
WriteError(er);
367367
}
368368
catch (SmtpException ex)
369369
{
370370
if (ex.InnerException != null)
371371
{
372-
ErrorRecord er = new ErrorRecord(new SmtpException(ex.InnerException.Message), "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
372+
ErrorRecord er = new(new SmtpException(ex.InnerException.Message), "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
373373
WriteError(er);
374374
}
375375
else
376376
{
377-
ErrorRecord er = new ErrorRecord(ex, "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
377+
ErrorRecord er = new(ex, "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
378378
WriteError(er);
379379
}
380380
}
381381
catch (InvalidOperationException ex)
382382
{
383-
ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, _mSmtpClient);
383+
ErrorRecord er = new(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, _mSmtpClient);
384384
WriteError(er);
385385
}
386386
catch (System.Security.Authentication.AuthenticationException ex)
387387
{
388-
ErrorRecord er = new ErrorRecord(ex, "AuthenticationException", ErrorCategory.InvalidOperation, _mSmtpClient);
388+
ErrorRecord er = new(ex, "AuthenticationException", ErrorCategory.InvalidOperation, _mSmtpClient);
389389
WriteError(er);
390390
}
391391
finally

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Set-PSBreakpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected override void BeginProcessing()
123123
protected override void ProcessRecord()
124124
{
125125
// If there is a script, resolve its path
126-
Collection<string> scripts = new Collection<string>();
126+
Collection<string> scripts = new();
127127

128128
if (Script != null)
129129
{

src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void ProcessRecord()
2323
// Create the alias info
2424

2525
AliasInfo aliasToSet =
26-
new AliasInfo(
26+
new(
2727
Name,
2828
Value,
2929
Context,

src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected override void ProcessRecord()
7777
}
7878
#else
7979
// build up the SystemTime struct to pass to SetSystemTime
80-
NativeMethods.SystemTime systemTime = new NativeMethods.SystemTime();
80+
NativeMethods.SystemTime systemTime = new();
8181
systemTime.Year = (UInt16)dateToUse.Year;
8282
systemTime.Month = (UInt16)dateToUse.Month;
8383
systemTime.Day = (UInt16)dateToUse.Day;
@@ -102,8 +102,8 @@ protected override void ProcessRecord()
102102
}
103103

104104
// output DateTime object wrapped in an PSObject with DisplayHint attached
105-
PSObject outputObj = new PSObject(dateToUse);
106-
PSNoteProperty note = new PSNoteProperty("DisplayHint", DisplayHint);
105+
PSObject outputObj = new(dateToUse);
106+
PSNoteProperty note = new("DisplayHint", DisplayHint);
107107
outputObj.Properties.Add(note);
108108

109109
WriteObject(outputObj);

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ShowCommandCommand : PSCmdlet, IDisposable
5050
/// <summary>
5151
/// Record the EndProcessing error.
5252
/// </summary>
53-
private PSDataCollection<ErrorRecord> _errors = new PSDataCollection<ErrorRecord>();
53+
private PSDataCollection<ErrorRecord> _errors = new();
5454

5555
/// <summary>
5656
/// Field used for the NoCommonParameter parameter.
@@ -174,7 +174,7 @@ protected override void BeginProcessing()
174174

175175
if (_showCommandProxy.ScreenHeight < this.Height)
176176
{
177-
ErrorRecord error = new ErrorRecord(
177+
ErrorRecord error = new(
178178
new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, FormatAndOut_out_gridview.PropertyValidate, "Height", _showCommandProxy.ScreenHeight)),
179179
"PARAMETER_DATA_ERROR",
180180
ErrorCategory.InvalidData,
@@ -184,7 +184,7 @@ protected override void BeginProcessing()
184184

185185
if (_showCommandProxy.ScreenWidth < this.Width)
186186
{
187-
ErrorRecord error = new ErrorRecord(
187+
ErrorRecord error = new(
188188
new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, FormatAndOut_out_gridview.PropertyValidate, "Width", _showCommandProxy.ScreenWidth)),
189189
"PARAMETER_DATA_ERROR",
190190
ErrorCategory.InvalidData,
@@ -233,7 +233,7 @@ protected override void EndProcessing()
233233
return;
234234
}
235235

236-
StringBuilder errorString = new StringBuilder();
236+
StringBuilder errorString = new();
237237

238238
for (int i = 0; i < _errors.Count; i++)
239239
{
@@ -268,7 +268,7 @@ protected override void StopProcessing()
268268
private void RunScriptSilentlyAndWithErrorHookup(string script)
269269
{
270270
// errors are not created here, because there is a field for it used in the final pop up
271-
PSDataCollection<object> output = new PSDataCollection<object>();
271+
PSDataCollection<object> output = new();
272272

273273
output.DataAdded += this.Output_DataAdded;
274274
_errors.DataAdded += this.Error_DataAdded;
@@ -286,7 +286,7 @@ private void RunScriptSilentlyAndWithErrorHookup(string script)
286286
/// </summary>
287287
private void IssueErrorForNoCommand()
288288
{
289-
InvalidOperationException errorException = new InvalidOperationException(
289+
InvalidOperationException errorException = new(
290290
string.Format(
291291
CultureInfo.CurrentUICulture,
292292
FormatAndOut_out_gridview.CommandNotFound,
@@ -299,7 +299,7 @@ private void IssueErrorForNoCommand()
299299
/// </summary>
300300
private void IssueErrorForMoreThanOneCommand()
301301
{
302-
InvalidOperationException errorException = new InvalidOperationException(
302+
InvalidOperationException errorException = new(
303303
string.Format(
304304
CultureInfo.CurrentUICulture,
305305
FormatAndOut_out_gridview.MoreThanOneCommand,

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void ProcessMarkdownInfo(MarkdownInfo markdownInfo)
168168

169169
try
170170
{
171-
ProcessStartInfo startInfo = new ProcessStartInfo();
171+
ProcessStartInfo startInfo = new();
172172
startInfo.FileName = tmpFilePath;
173173
startInfo.UseShellExecute = true;
174174
Process.Start(startInfo);

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Sort-Object.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private int Heapify(List<OrderByPropertyEntry> dataToSort, OrderByPropertyCompar
239239
/// </summary>
240240
protected override void EndProcessing()
241241
{
242-
OrderByProperty orderByProperty = new OrderByProperty(
242+
OrderByProperty orderByProperty = new(
243243
this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);
244244

245245
var dataToProcess = orderByProperty.OrderMatrix;

src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Dispose()
6464

6565
// object used for synchronizes pipeline thread and stop thread
6666
// access to waitHandle
67-
private readonly object _syncObject = new object();
67+
private readonly object _syncObject = new();
6868

6969
// this is set to true by stopProcessing
7070
private bool _stopping = false;

src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ e is NotSupportedException ||
115115
e is SecurityException
116116
)
117117
{
118-
Exception exception = new Exception(
118+
Exception exception = new(
119119
string.Format(
120120
CultureInfo.CurrentUICulture,
121121
TestJsonCmdletStrings.JsonSchemaFileOpenFailure,
@@ -125,7 +125,7 @@ e is SecurityException
125125
}
126126
catch (Exception e)
127127
{
128-
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJsonSchema, e);
128+
Exception exception = new(TestJsonCmdletStrings.InvalidJsonSchema, e);
129129
ThrowTerminatingError(new ErrorRecord(exception, "InvalidJsonSchema", ErrorCategory.InvalidData, resolvedpath));
130130
}
131131
}
@@ -149,11 +149,11 @@ protected override void ProcessRecord()
149149
{
150150
result = false;
151151

152-
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJsonAgainstSchema);
152+
Exception exception = new(TestJsonCmdletStrings.InvalidJsonAgainstSchema);
153153

154154
foreach (var message in errorMessages)
155155
{
156-
ErrorRecord errorRecord = new ErrorRecord(exception, "InvalidJsonAgainstSchema", ErrorCategory.InvalidData, null);
156+
ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchema", ErrorCategory.InvalidData, null);
157157
errorRecord.ErrorDetails = new ErrorDetails(message.ToString());
158158
WriteError(errorRecord);
159159
}
@@ -164,7 +164,7 @@ protected override void ProcessRecord()
164164
{
165165
result = false;
166166

167-
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJson, exc);
167+
Exception exception = new(TestJsonCmdletStrings.InvalidJson, exc);
168168
WriteError(new ErrorRecord(exception, "InvalidJson", ErrorCategory.InvalidData, Json));
169169
}
170170

0 commit comments

Comments
 (0)