Skip to content

Commit 2f6d0ac

Browse files
authored
1 parent b5fc2f3 commit 2f6d0ac

22 files changed

+105
-105
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.PowerShell.Commands
2020
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2097109", RemotingCapability = RemotingCapability.None)]
2121
public class AddMemberCommand : PSCmdlet
2222
{
23-
private static readonly object s_notSpecified = new object();
23+
private static readonly object s_notSpecified = new();
2424

2525
private static bool HasBeenSpecified(object obj)
2626
{
@@ -221,7 +221,7 @@ private void EnsureValue1HasBeenSpecified()
221221
{
222222
if (!HasBeenSpecified(_value1))
223223
{
224-
Collection<FieldDescription> fdc = new Collection<FieldDescription>();
224+
Collection<FieldDescription> fdc = new();
225225
fdc.Add(new FieldDescription("Value"));
226226
string prompt = StringUtil.Format(AddMember.Value1Prompt, _memberType);
227227
Dictionary<string, PSObject> result = this.Host.UI.Prompt(prompt, null, fdc);
@@ -531,9 +531,9 @@ private void UpdateTypeNames()
531531

532532
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args)
533533
{
534-
ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly,
534+
ErrorDetails details = new(this.GetType().GetTypeInfo().Assembly,
535535
"Microsoft.PowerShell.Commands.Utility.resources.AddMember", resourceId, args);
536-
ErrorRecord errorRecord = new ErrorRecord(
536+
ErrorRecord errorRecord = new(
537537
new InvalidOperationException(details.Message),
538538
errorId,
539539
ErrorCategory.InvalidOperation,

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public string[] Path
153153

154154
string[] pathValue = value;
155155

156-
List<string> resolvedPaths = new List<string>();
156+
List<string> resolvedPaths = new();
157157

158158
// Verify that the paths are resolved and valid
159159
foreach (string path in pathValue)
@@ -198,7 +198,7 @@ public string[] LiteralPath
198198
return;
199199
}
200200

201-
List<string> resolvedPaths = new List<string>();
201+
List<string> resolvedPaths = new();
202202
foreach (string path in value)
203203
{
204204
string literalPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(path);
@@ -230,7 +230,7 @@ private void ProcessPaths(List<string> resolvedPaths)
230230

231231
// Throw an error if it is an unrecognized extension
232232
default:
233-
ErrorRecord errorRecord = new ErrorRecord(
233+
ErrorRecord errorRecord = new(
234234
new Exception(
235235
StringUtil.Format(AddTypeStrings.FileExtensionNotSupported, currentExtension)),
236236
"EXTENSION_NOT_SUPPORTED",
@@ -248,7 +248,7 @@ private void ProcessPaths(List<string> resolvedPaths)
248248
else if (!string.Equals(activeExtension, currentExtension, StringComparison.OrdinalIgnoreCase))
249249
{
250250
// All files must have the same extension otherwise throw.
251-
ErrorRecord errorRecord = new ErrorRecord(
251+
ErrorRecord errorRecord = new(
252252
new Exception(
253253
StringUtil.Format(AddTypeStrings.MultipleExtensionsNotSupported)),
254254
"MULTIPLE_EXTENSION_NOT_SUPPORTED",
@@ -327,7 +327,7 @@ public string OutputAssembly
327327

328328
// Try to resolve the path
329329
ProviderInfo provider = null;
330-
Collection<string> newPaths = new Collection<string>();
330+
Collection<string> newPaths = new();
331331

332332
try
333333
{
@@ -336,7 +336,7 @@ public string OutputAssembly
336336
// Ignore the ItemNotFound -- we handle it.
337337
catch (ItemNotFoundException) { }
338338

339-
ErrorRecord errorRecord = new ErrorRecord(
339+
ErrorRecord errorRecord = new(
340340
new Exception(
341341
StringUtil.Format(AddTypeStrings.OutputAssemblyDidNotResolve, _outputAssembly)),
342342
"INVALID_OUTPUT_ASSEMBLY",
@@ -520,7 +520,7 @@ private static string GetUsingTemplate(Language language)
520520
// Generate the code for the using statements
521521
private string GetUsingSet(Language language)
522522
{
523-
StringBuilder usingNamespaceSet = new StringBuilder();
523+
StringBuilder usingNamespaceSet = new();
524524

525525
switch (language)
526526
{
@@ -578,7 +578,7 @@ protected override void EndProcessing()
578578
// assembly type without an output assembly
579579
if (string.IsNullOrEmpty(_outputAssembly) && this.MyInvocation.BoundParameters.ContainsKey(nameof(OutputType)))
580580
{
581-
ErrorRecord errorRecord = new ErrorRecord(
581+
ErrorRecord errorRecord = new(
582582
new Exception(
583583
string.Format(
584584
CultureInfo.CurrentCulture,
@@ -630,21 +630,21 @@ protected override void EndProcessing()
630630
private static readonly string s_frameworkFolder = PathType.GetDirectoryName(typeof(object).Assembly.Location);
631631

632632
// These assemblies are always automatically added to ReferencedAssemblies.
633-
private static readonly Lazy<PortableExecutableReference[]> s_autoReferencedAssemblies = new Lazy<PortableExecutableReference[]>(InitAutoIncludedRefAssemblies);
633+
private static readonly Lazy<PortableExecutableReference[]> s_autoReferencedAssemblies = new(InitAutoIncludedRefAssemblies);
634634

635635
// A HashSet of assembly names to be ignored if they are specified in '-ReferencedAssemblies'
636-
private static readonly Lazy<HashSet<string>> s_refAssemblyNamesToIgnore = new Lazy<HashSet<string>>(InitRefAssemblyNamesToIgnore);
636+
private static readonly Lazy<HashSet<string>> s_refAssemblyNamesToIgnore = new(InitRefAssemblyNamesToIgnore);
637637

638638
// These assemblies are used, when ReferencedAssemblies parameter is not specified.
639-
private static readonly Lazy<IEnumerable<PortableExecutableReference>> s_defaultAssemblies = new Lazy<IEnumerable<PortableExecutableReference>>(InitDefaultRefAssemblies);
639+
private static readonly Lazy<IEnumerable<PortableExecutableReference>> s_defaultAssemblies = new(InitDefaultRefAssemblies);
640640

641641
private bool InMemory { get { return string.IsNullOrEmpty(_outputAssembly); } }
642642

643643
// These dictionaries prevent reloading already loaded and unchanged code.
644644
// We don't worry about unbounded growing of the cache because in .Net Core 2.0 we can not unload assemblies.
645645
// TODO: review if we will be able to unload assemblies after migrating to .Net Core 2.1.
646-
private static readonly HashSet<string> s_sourceTypesCache = new HashSet<string>();
647-
private static readonly Dictionary<int, Assembly> s_sourceAssemblyCache = new Dictionary<int, Assembly>();
646+
private static readonly HashSet<string> s_sourceTypesCache = new();
647+
private static readonly Dictionary<int, Assembly> s_sourceAssemblyCache = new();
648648

649649
private static readonly string s_defaultSdkDirectory = Utils.DefaultPowerShellAppBase;
650650

@@ -995,7 +995,7 @@ private void SourceCodeProcessing()
995995
}
996996

997997
SourceText sourceText;
998-
List<SyntaxTree> syntaxTrees = new List<SyntaxTree>();
998+
List<SyntaxTree> syntaxTrees = new();
999999

10001000
switch (ParameterSetName)
10011001
{
@@ -1074,12 +1074,12 @@ private void CompileToAssembly(List<SyntaxTree> syntaxTrees, CompilationOptions
10741074

10751075
private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<string> newTypes)
10761076
{
1077-
AllNamedTypeSymbolsVisitor visitor = new AllNamedTypeSymbolsVisitor();
1077+
AllNamedTypeSymbolsVisitor visitor = new();
10781078
visitor.Visit(compilation.Assembly.GlobalNamespace);
10791079

10801080
foreach (var symbolName in visitor.DuplicateSymbols)
10811081
{
1082-
ErrorRecord errorRecord = new ErrorRecord(
1082+
ErrorRecord errorRecord = new(
10831083
new Exception(
10841084
string.Format(AddTypeStrings.TypeAlreadyExists, symbolName)),
10851085
"TYPE_ALREADY_EXISTS",
@@ -1090,7 +1090,7 @@ private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<stri
10901090

10911091
if (!visitor.DuplicateSymbols.IsEmpty)
10921092
{
1093-
ErrorRecord errorRecord = new ErrorRecord(
1093+
ErrorRecord errorRecord = new(
10941094
new InvalidOperationException(AddTypeStrings.CompilerErrors),
10951095
"COMPILER_ERRORS",
10961096
ErrorCategory.InvalidData,
@@ -1106,8 +1106,8 @@ private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<stri
11061106
// Visit symbols in all namespaces and collect duplicates.
11071107
private class AllNamedTypeSymbolsVisitor : SymbolVisitor
11081108
{
1109-
public readonly ConcurrentBag<string> DuplicateSymbols = new ConcurrentBag<string>();
1110-
public readonly ConcurrentBag<string> UniqueSymbols = new ConcurrentBag<string>();
1109+
public readonly ConcurrentBag<string> DuplicateSymbols = new();
1110+
public readonly ConcurrentBag<string> UniqueSymbols = new();
11111111

11121112
public override void VisitNamespace(INamespaceSymbol symbol)
11131113
{
@@ -1243,7 +1243,7 @@ private void HandleCompilerErrors(ImmutableArray<Diagnostic> compilerDiagnostics
12431243
}
12441244
else
12451245
{
1246-
ErrorRecord errorRecord = new ErrorRecord(
1246+
ErrorRecord errorRecord = new(
12471247
new Exception(errorText),
12481248
"SOURCE_CODE_ERROR",
12491249
ErrorCategory.InvalidData,
@@ -1255,7 +1255,7 @@ private void HandleCompilerErrors(ImmutableArray<Diagnostic> compilerDiagnostics
12551255

12561256
if (IsError)
12571257
{
1258-
ErrorRecord errorRecord = new ErrorRecord(
1258+
ErrorRecord errorRecord = new(
12591259
new InvalidOperationException(AddTypeStrings.CompilerErrors),
12601260
"COMPILER_ERRORS",
12611261
ErrorCategory.InvalidData,
@@ -1288,7 +1288,7 @@ private static string BuildErrorMessage(Diagnostic diagnisticRecord)
12881288
var errorLineString = textLines[errorLineNumber].ToString();
12891289
var errorPosition = lineSpan.StartLinePosition.Character;
12901290

1291-
StringBuilder sb = new StringBuilder(diagnisticMessage.Length + errorLineString.Length * 2 + 4);
1291+
StringBuilder sb = new(diagnisticMessage.Length + errorLineString.Length * 2 + 4);
12921292

12931293
sb.AppendLine(diagnisticMessage);
12941294
sb.AppendLine(errorLineString);
@@ -1314,7 +1314,7 @@ private static string BuildErrorMessage(Diagnostic diagnisticRecord)
13141314
private static int SyntaxTreeArrayGetHashCode(IEnumerable<SyntaxTree> sts)
13151315
{
13161316
// We use our extension method EnumerableExtensions.SequenceGetHashCode<T>().
1317-
List<int> stHashes = new List<int>();
1317+
List<int> stHashes = new();
13181318
foreach (var st in sts)
13191319
{
13201320
stHashes.Add(SyntaxTreeGetHashCode(st));

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public SwitchParameter PassThru
101101
private List<OrderByPropertyEntry> _referenceEntries;
102102

103103
private readonly List<OrderByPropertyEntry> _referenceEntryBacklog
104-
= new List<OrderByPropertyEntry>();
104+
= new();
105105

106106
private readonly List<OrderByPropertyEntry> _differenceEntryBacklog
107-
= new List<OrderByPropertyEntry>();
107+
= new();
108108

109109
private OrderByProperty _orderByProperty = null;
110110
private OrderByPropertyComparer _comparer = null;
@@ -256,7 +256,7 @@ private void InitComparer()
256256
if (_comparer != null)
257257
return;
258258

259-
List<PSObject> referenceObjectList = new List<PSObject>(ReferenceObject);
259+
List<PSObject> referenceObjectList = new(ReferenceObject);
260260
_orderByProperty = new OrderByProperty(
261261
this, referenceObjectList, Property, true, _cultureInfo, CaseSensitive);
262262
Diagnostics.Assert(_orderByProperty.Comparer != null, "no comparer");
@@ -327,7 +327,7 @@ private void Emit(OrderByPropertyEntry entry, string sideIndicator)
327327
mshobj = new PSObject();
328328
if (Property == null || Property.Length == 0)
329329
{
330-
PSNoteProperty inputNote = new PSNoteProperty(
330+
PSNoteProperty inputNote = new(
331331
InputObjectPropertyName, entry.inputObject);
332332
mshobj.Properties.Add(inputNote);
333333
}
@@ -348,7 +348,7 @@ private void Emit(OrderByPropertyEntry entry, string sideIndicator)
348348
object prop = hash[FormatParameterDefinitionKeys.ExpressionEntryKey];
349349
Diagnostics.Assert(prop != null, "null prop");
350350
string propName = prop.ToString();
351-
PSNoteProperty propertyNote = new PSNoteProperty(
351+
PSNoteProperty propertyNote = new(
352352
propName,
353353
entry.orderValues[i].PropertyValue);
354354
try
@@ -364,7 +364,7 @@ private void Emit(OrderByPropertyEntry entry, string sideIndicator)
364364
}
365365

366366
mshobj.Properties.Remove(SideIndicatorPropertyName);
367-
PSNoteProperty sideNote = new PSNoteProperty(
367+
PSNoteProperty sideNote = new(
368368
SideIndicatorPropertyName, sideIndicator);
369369
mshobj.Properties.Add(sideNote);
370370
WriteObject(mshobj);
@@ -411,7 +411,7 @@ protected override void ProcessRecord()
411411
InitComparer();
412412
}
413413

414-
List<PSObject> differenceList = new List<PSObject>(DifferenceObject);
414+
List<PSObject> differenceList = new(DifferenceObject);
415415
List<OrderByPropertyEntry> differenceEntries =
416416
OrderByProperty.CreateOrderMatrix(
417417
this, differenceList, _orderByProperty.MshParameterList);
@@ -459,7 +459,7 @@ private void HandleDifferenceObjectOnly()
459459
return;
460460
}
461461

462-
List<PSObject> differenceList = new List<PSObject>(DifferenceObject);
462+
List<PSObject> differenceList = new(DifferenceObject);
463463
_orderByProperty = new OrderByProperty(
464464
this, differenceList, Property, true, _cultureInfo, CaseSensitive);
465465
List<OrderByPropertyEntry> differenceEntries =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public ConsoleColorCmdlet()
9292
private static ErrorRecord BuildOutOfRangeErrorRecord(object val, string errorId)
9393
{
9494
string msg = StringUtil.Format(HostStrings.InvalidColorErrorTemplate, val.ToString());
95-
ArgumentOutOfRangeException e = new ArgumentOutOfRangeException("value", val, msg);
95+
ArgumentOutOfRangeException e = new("value", val, msg);
9696
return new ErrorRecord(e, errorId, ErrorCategory.InvalidArgument, null);
9797
}
9898
#endregion helper

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFrom-SddlString.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ private static string ConvertToNTAccount(SecurityIdentifier securityIdentifier)
5757

5858
private static List<string> GetApplicableAccessRights(int accessMask, AccessRightTypeNames? typeName)
5959
{
60-
List<Type> typesToExamine = new List<Type>();
61-
List<string> foundAccessRightNames = new List<string>();
62-
HashSet<int> foundAccessRightValues = new HashSet<int>();
60+
List<Type> typesToExamine = new();
61+
List<string> foundAccessRightNames = new();
62+
HashSet<int> foundAccessRightValues = new();
6363

6464
if (typeName != null)
6565
{
@@ -121,10 +121,10 @@ private static string[] ConvertAccessControlListToStrings(CommonAcl acl, AccessR
121121
return Array.Empty<string>();
122122
}
123123

124-
List<string> aceStringList = new List<string>(acl.Count);
124+
List<string> aceStringList = new(acl.Count);
125125
foreach (CommonAce ace in acl)
126126
{
127-
StringBuilder aceString = new StringBuilder();
127+
StringBuilder aceString = new();
128128
string ntAccount = ConvertToNTAccount(ace.SecurityIdentifier);
129129
aceString.Append($"{ntAccount}: {ace.AceQualifier}");
130130

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFrom-StringData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public string StringData
4747
/// </summary>
4848
protected override void ProcessRecord()
4949
{
50-
Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase);
50+
Hashtable result = new(StringComparer.OrdinalIgnoreCase);
5151

5252
if (string.IsNullOrEmpty(_stringData))
5353
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected override void ProcessRecord()
106106
else
107107
{
108108
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.InvalidInputObjectType, baseObj.GetType());
109-
ErrorRecord errorRecord = new ErrorRecord(
109+
ErrorRecord errorRecord = new(
110110
new InvalidDataException(errorMessage),
111111
"InvalidInputObject",
112112
ErrorCategory.InvalidData,
@@ -150,7 +150,7 @@ private async Task<string> ReadContentFromFile(string filePath)
150150

151151
try
152152
{
153-
using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
153+
using (StreamReader reader = new(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
154154
{
155155
string mdContent = await reader.ReadToEndAsync();
156156
return mdContent;
@@ -189,7 +189,7 @@ private List<string> ResolvePath(string path, bool isLiteral)
189189
{
190190
ProviderInfo provider = null;
191191
PSDriveInfo drive = null;
192-
List<string> resolvedPaths = new List<string>();
192+
List<string> resolvedPaths = new();
193193

194194
try
195195
{
@@ -216,7 +216,7 @@ private List<string> ResolvePath(string path, bool isLiteral)
216216
if (!provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase))
217217
{
218218
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.FileSystemPathsOnly, path);
219-
ErrorRecord errorRecord = new ErrorRecord(
219+
ErrorRecord errorRecord = new(
220220
new ArgumentException(),
221221
"OnlyFileSystemPathsSupported",
222222
ErrorCategory.InvalidArgument,

0 commit comments

Comments
 (0)