Skip to content

Commit bcdc71e

Browse files
committed
Fix IDE0090: Simplify new expression part 4.3
`src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/` Contributes to PowerShell#14202. https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0090
1 parent fa657ef commit bcdc71e

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override void Write(string output)
8787
}
8888
}
8989

90-
private readonly StringBuilder _cachedWrite = new StringBuilder();
90+
private readonly StringBuilder _cachedWrite = new();
9191

9292
/// <summary>
9393
/// Sends the given output string to the host for processing.

src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceCommandBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal Collection<PSTraceSource> GetMatchingTraceSource(
5656
{
5757
notMatched = new Collection<string>();
5858

59-
Collection<PSTraceSource> results = new Collection<PSTraceSource>();
59+
Collection<PSTraceSource> results = new();
6060
foreach (string patternToMatch in patternsToMatch)
6161
{
6262
bool matchFound = false;
@@ -102,12 +102,12 @@ internal Collection<PSTraceSource> GetMatchingTraceSource(
102102
!WildcardPattern.ContainsWildcardCharacters(patternToMatch))
103103
{
104104
ItemNotFoundException itemNotFound =
105-
new ItemNotFoundException(
105+
new(
106106
patternToMatch,
107107
"TraceSourceNotFound",
108108
SessionStateStrings.TraceSourceNotFound);
109109

110-
ErrorRecord errorRecord = new ErrorRecord(itemNotFound.ErrorRecord, itemNotFound);
110+
ErrorRecord errorRecord = new(itemNotFound.ErrorRecord, itemNotFound);
111111
WriteError(errorRecord);
112112
}
113113
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,6 @@ private static ErrorRecord ConvertToErrorRecord(object obj)
541541
private readonly TraceListenerCommandBase _cmdlet;
542542
private readonly bool _writeError;
543543
private bool _isOpen = true;
544-
private readonly Collection<PSTraceSource> _matchingSources = new Collection<PSTraceSource>();
544+
private readonly Collection<PSTraceSource> _matchingSources = new();
545545
}
546546
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ internal void AddTraceListenersToSources(Collection<PSTraceSource> matchingSourc
229229

230230
try
231231
{
232-
Collection<string> resolvedPaths = new Collection<string>();
232+
Collection<string> resolvedPaths = new();
233233
try
234234
{
235235
// Resolve the file path
@@ -287,7 +287,7 @@ internal void AddTraceListenersToSources(Collection<PSTraceSource> matchingSourc
287287
if (ForceWrite && System.IO.File.Exists(resolvedPath))
288288
{
289289
// remove readonly attributes on the file
290-
System.IO.FileInfo fInfo = new System.IO.FileInfo(resolvedPath);
290+
System.IO.FileInfo fInfo = new(resolvedPath);
291291
if (fInfo != null)
292292
{
293293
// Save some disk write time by checking whether file is readonly..
@@ -300,13 +300,13 @@ internal void AddTraceListenersToSources(Collection<PSTraceSource> matchingSourc
300300
}
301301

302302
// Trace commands always append..So there is no need to set overwrite with force..
303-
FileStream fileStream = new FileStream(resolvedPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
303+
FileStream fileStream = new(resolvedPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
304304
FileStreams.Add(fileStream);
305305

306306
// Open the file stream
307307

308308
TextWriterTraceListener fileListener =
309-
new TextWriterTraceListener(fileStream, resolvedPath);
309+
new(fileStream, resolvedPath);
310310

311311
fileListener.Name = FileListener;
312312

@@ -328,7 +328,7 @@ internal void AddTraceListenersToSources(Collection<PSTraceSource> matchingSourc
328328
if (fileOpenError != null)
329329
{
330330
ErrorRecord errorRecord =
331-
new ErrorRecord(
331+
new(
332332
fileOpenError,
333333
"FileListenerPathResolutionFailed",
334334
ErrorCategory.OpenError,
@@ -353,7 +353,7 @@ internal void AddTraceListenersToSources(Collection<PSTraceSource> matchingSourc
353353
if (error != null)
354354
{
355355
ErrorRecord errorRecord =
356-
new ErrorRecord(
356+
new(
357357
error,
358358
"FileListenerPathResolutionFailed",
359359
ErrorCategory.InvalidArgument,
@@ -491,7 +491,7 @@ internal void TurnOnTracing(Collection<PSTraceSource> matchingSources, bool preC
491491
{
492492
// Copy the listeners into a different collection
493493

494-
Collection<TraceListener> listenerCollection = new Collection<TraceListener>();
494+
Collection<TraceListener> listenerCollection = new();
495495
foreach (TraceListener listener in source.Listeners)
496496
{
497497
listenerCollection.Add(listener);
@@ -596,7 +596,7 @@ protected void ClearStoredState()
596596
}
597597

598598
private readonly Dictionary<PSTraceSource, KeyValuePair<PSTraceSourceOptions, Collection<TraceListener>>> _storedTraceSourceState =
599-
new Dictionary<PSTraceSource, KeyValuePair<PSTraceSourceOptions, Collection<TraceListener>>>();
599+
new();
600600

601601
#endregion stored state
602602
}

0 commit comments

Comments
 (0)