Skip to content

Commit bb78d4b

Browse files
authored
1 parent b007952 commit bb78d4b

8 files changed

Lines changed: 97 additions & 96 deletions

File tree

src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private PowerShellAssemblyLoadContext(string basePaths)
105105

106106
#region Fields
107107

108-
private static readonly object s_syncObj = new object();
108+
private static readonly object s_syncObj = new();
109109
private readonly string[] _probingPaths;
110110
private readonly string[] _extensions = new string[] { ".ni.dll", ".dll" };
111111
// CoreCLR type catalog dictionary
@@ -114,9 +114,8 @@ private PowerShellAssemblyLoadContext(string basePaths)
114114
private readonly Dictionary<string, string> _coreClrTypeCatalog;
115115
private readonly Lazy<HashSet<string>> _availableDotNetAssemblyNames;
116116

117-
private readonly HashSet<string> _denyListedAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase){
118-
"System.Windows.Forms"
119-
};
117+
private readonly HashSet<string> _denyListedAssemblies =
118+
new(StringComparer.OrdinalIgnoreCase) { "System.Windows.Forms" };
120119

121120
#if !UNIX
122121
private string _winDir;
@@ -140,7 +139,7 @@ private PowerShellAssemblyLoadContext(string basePaths)
140139
/// Therefore, there is no need to use the full assembly name as the key. Short assembly name is sufficient.
141140
/// </remarks>
142141
private static readonly ConcurrentDictionary<string, Assembly> s_assemblyCache =
143-
new ConcurrentDictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
142+
new(StringComparer.OrdinalIgnoreCase);
144143

145144
#endregion Fields
146145

@@ -509,7 +508,7 @@ private static Assembly GetTrustedPlatformAssembly(string tpaStrongName)
509508
// it back from the cache of default context.
510509
// - If the requested TPA is not loaded yet, then 'Assembly.Load' will make the
511510
// default context to load it
512-
AssemblyName assemblyName = new AssemblyName(tpaStrongName);
511+
AssemblyName assemblyName = new(tpaStrongName);
513512
Assembly asmLoaded = Assembly.Load(assemblyName);
514513
return asmLoaded;
515514
}

src/System.Management.Automation/CoreCLR/CorePsPlatform.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,20 @@ public static bool IsWindowsDesktop
155155
#endif
156156

157157
// format files
158-
internal static readonly List<string> FormatFileNames = new List<string>
159-
{
160-
"Certificate.format.ps1xml",
161-
"Diagnostics.format.ps1xml",
162-
"DotNetTypes.format.ps1xml",
163-
"Event.format.ps1xml",
164-
"FileSystem.format.ps1xml",
165-
"Help.format.ps1xml",
166-
"HelpV3.format.ps1xml",
167-
"PowerShellCore.format.ps1xml",
168-
"PowerShellTrace.format.ps1xml",
169-
"Registry.format.ps1xml",
170-
"WSMan.format.ps1xml"
171-
};
158+
internal static readonly List<string> FormatFileNames = new()
159+
{
160+
"Certificate.format.ps1xml",
161+
"Diagnostics.format.ps1xml",
162+
"DotNetTypes.format.ps1xml",
163+
"Event.format.ps1xml",
164+
"FileSystem.format.ps1xml",
165+
"Help.format.ps1xml",
166+
"HelpV3.format.ps1xml",
167+
"PowerShellCore.format.ps1xml",
168+
"PowerShellTrace.format.ps1xml",
169+
"Registry.format.ps1xml",
170+
"WSMan.format.ps1xml"
171+
};
172172

173173
/// <summary>
174174
/// Some common environment variables used in PS have different
@@ -566,8 +566,8 @@ internal static int NonWindowsGetProcessParentPid(int pid)
566566
/// <summary>Unix specific implementations of required functionality.</summary>
567567
internal static class Unix
568568
{
569-
private static Dictionary<int, string> usernameCache = new Dictionary<int, string>();
570-
private static Dictionary<int, string> groupnameCache = new Dictionary<int, string>();
569+
private static Dictionary<int, string> usernameCache = new();
570+
private static Dictionary<int, string> groupnameCache = new();
571571

572572
/// <summary>The type of a Unix file system item.</summary>
573573
public enum ItemType
@@ -699,7 +699,7 @@ public class CommonStat
699699
private const char CanExecute = 'x';
700700

701701
// helper for getting unix mode
702-
private Dictionary<StatMask, char> modeMap = new Dictionary<StatMask, char>()
702+
private Dictionary<StatMask, char> modeMap = new()
703703
{
704704
{ StatMask.OwnerRead, CanRead },
705705
{ StatMask.OwnerWrite, CanWrite },
@@ -726,7 +726,7 @@ public class CommonStat
726726
};
727727

728728
// The item type and the character representation for the first element in the stat string
729-
private Dictionary<ItemType, char> itemTypeTable = new Dictionary<ItemType, char>()
729+
private Dictionary<ItemType, char> itemTypeTable = new()
730730
{
731731
{ ItemType.BlockDevice, 'b' },
732732
{ ItemType.CharacterDevice, 'c' },
@@ -860,7 +860,7 @@ public static bool IsHardLink(FileSystemInfo fs)
860860
/// <returns>A managed common stat class instance.</returns>
861861
private static CommonStat CopyStatStruct(NativeMethods.CommonStatStruct css)
862862
{
863-
CommonStat cs = new CommonStat();
863+
CommonStat cs = new();
864864
cs.Inode = css.Inode;
865865
cs.Mode = css.Mode;
866866
cs.UserId = css.UserId;

src/System.Management.Automation/DscSupport/CimDSCParser.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,19 @@ public static class DscClassCache
544544

545545
// Create a list of classes which are not actual DSC resources similar to what we do inside PSDesiredStateConfiguration.psm1
546546
private static readonly string[] s_hiddenResourceList =
547-
{
548-
"MSFT_BaseConfigurationProviderRegistration",
549-
"MSFT_CimConfigurationProviderRegistration",
550-
"MSFT_PSConfigurationProviderRegistration",
551-
};
547+
{
548+
"MSFT_BaseConfigurationProviderRegistration",
549+
"MSFT_CimConfigurationProviderRegistration",
550+
"MSFT_PSConfigurationProviderRegistration",
551+
};
552552

553553
// Create a HashSet for fast lookup. According to MSDN, the time complexity of search for an element in a HashSet is O(1)
554-
private static readonly HashSet<string> s_hiddenResourceCache = new HashSet<string>(s_hiddenResourceList,
555-
StringComparer.OrdinalIgnoreCase);
554+
private static readonly HashSet<string> s_hiddenResourceCache =
555+
new(s_hiddenResourceList, StringComparer.OrdinalIgnoreCase);
556556

557557
// a collection to hold current importing script based resource file
558558
// this prevent circular importing case when the script resource existing in the same module with resources it import-dscresource
559-
private static readonly HashSet<string> s_currentImportingScriptFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
559+
private static readonly HashSet<string> s_currentImportingScriptFiles = new(StringComparer.OrdinalIgnoreCase);
560560

561561
/// <summary>
562562
/// DSC class cache for this runspace.
@@ -638,18 +638,20 @@ private static HashSet<string> ScriptKeywordFileCache
638638
/// <summary>
639639
/// Default ModuleName and ModuleVersion to use.
640640
/// </summary>
641-
private static readonly Tuple<string, Version> s_defaultModuleInfoForResource = new Tuple<string, Version>("PSDesiredStateConfiguration", new Version("1.1"));
641+
private static readonly Tuple<string, Version> s_defaultModuleInfoForResource =
642+
new("PSDesiredStateConfiguration", new Version("1.1"));
642643

643644
/// <summary>
644645
/// Default ModuleName and ModuleVersion to use for meta configuration resources.
645646
/// </summary>
646-
internal static readonly Tuple<string, Version> DefaultModuleInfoForMetaConfigResource = new Tuple<string, Version>("PSDesiredStateConfigurationEngine", new Version("2.0"));
647+
internal static readonly Tuple<string, Version> DefaultModuleInfoForMetaConfigResource =
648+
new("PSDesiredStateConfigurationEngine", new Version("2.0"));
647649

648650
/// <summary>
649651
/// A set of dynamic keywords that can be used in both configuration and meta configuration.
650652
/// </summary>
651653
internal static readonly HashSet<string> SystemResourceNames =
652-
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Node", "OMI_ConfigurationDocument" };
654+
new(StringComparer.OrdinalIgnoreCase) { "Node", "OMI_ConfigurationDocument" };
653655

654656
/// <summary>
655657
/// When this property is set to true, DSC Cache will cache multiple versions of a resource.
@@ -784,7 +786,7 @@ public static void Initialize(Collection<Exception> errors, List<string> moduleP
784786

785787
// Load Regular and DSC PS modules
786788
bool importInBoxResourcesImplicitly = false;
787-
List<string> modulePaths = new List<string>();
789+
List<string> modulePaths = new();
788790
if (modulePathList == null || modulePathList.Count == 0)
789791
{
790792
modulePaths.Add(Path.Combine(configSystemPath, inboxModulePath));
@@ -1131,7 +1133,7 @@ private static List<DscClassCacheEntry> GetCachedClasses()
11311133
/// <returns>List of cached cim classes.</returns>
11321134
public static List<Microsoft.Management.Infrastructure.CimClass> GetCachedClassesForModule(PSModuleInfo module)
11331135
{
1134-
List<Microsoft.Management.Infrastructure.CimClass> cachedClasses = new List<Microsoft.Management.Infrastructure.CimClass>();
1136+
List<Microsoft.Management.Infrastructure.CimClass> cachedClasses = new();
11351137
var moduleQualifiedName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", module.Name, module.Version.ToString());
11361138
foreach (var dscClassCacheEntry in ClassCache)
11371139
{
@@ -1151,7 +1153,7 @@ private static List<DscClassCacheEntry> GetCachedClasses()
11511153
/// <returns></returns>
11521154
public static List<string> GetFileDefiningClass(string className)
11531155
{
1154-
List<string> files = new List<string>();
1156+
List<string> files = new();
11551157
foreach (var pair in ByFileClassCache)
11561158
{
11571159
var file = pair.Key;
@@ -1298,7 +1300,7 @@ private static string GetFriendlyName(CimClass cimClass)
12981300
/// </summary>
12991301
public static Collection<DynamicKeyword> GetCachedKeywords()
13001302
{
1301-
Collection<DynamicKeyword> keywords = new Collection<DynamicKeyword>();
1303+
Collection<DynamicKeyword> keywords = new();
13021304

13031305
foreach (KeyValuePair<string, DscClassCacheEntry> cachedClass in ClassCache)
13041306
{
@@ -1909,7 +1911,7 @@ private static ParseError[] ImportResourceCheckSemantics(DynamicKeywordStatement
19091911
// This function performs semantic checks for all DSC Resources keywords.
19101912
private static ParseError[] CheckMandatoryPropertiesPresent(DynamicKeywordStatementAst kwAst)
19111913
{
1912-
HashSet<string> mandatoryPropertiesNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
1914+
HashSet<string> mandatoryPropertiesNames = new(StringComparer.OrdinalIgnoreCase);
19131915
foreach (var pair in kwAst.Keyword.Properties)
19141916
{
19151917
if (pair.Value.Mandatory)
@@ -2361,7 +2363,7 @@ private static void GenerateMofForAst(TypeDefinitionAst typeAst, StringBuilder s
23612363

23622364
ProcessMembers(sb, embeddedInstanceTypes, typeAst, className);
23632365

2364-
Queue<object> bases = new Queue<object>();
2366+
Queue<object> bases = new();
23652367
foreach (var b in typeAst.BaseTypes)
23662368
{
23672369
bases.Enqueue(b);
@@ -2459,7 +2461,7 @@ public static bool GetResourceMethodsLinePosition(PSModuleInfo moduleInfo, strin
24592461
}
24602462

24612463
IEnumerable<Ast> resourceDefinitions;
2462-
List<string> moduleFiles = new List<string>();
2464+
List<string> moduleFiles = new();
24632465
if (moduleInfo.RootModule != null)
24642466
{
24652467
moduleFiles.Add(moduleInfo.Path);
@@ -2593,7 +2595,7 @@ private static bool GetResourceDefinitionsFromModule(string fileName, out IEnume
25932595
{
25942596
if (errorList != null && extent != null)
25952597
{
2596-
List<string> errorMessages = new List<string>();
2598+
List<string> errorMessages = new();
25972599
foreach (var error in errors)
25982600
{
25992601
errorMessages.Add(error.ToString());
@@ -2698,7 +2700,7 @@ private static bool ImportKeywordsFromScriptFile(string fileName, PSModuleInfo m
26982700
return result;
26992701
}
27002702

2701-
private static readonly Dictionary<Type, string> s_mapPrimitiveDotNetTypeToMof = new Dictionary<Type, string>()
2703+
private static readonly Dictionary<Type, string> s_mapPrimitiveDotNetTypeToMof = new()
27022704
{
27032705
{ typeof(sbyte), "sint8" },
27042706
{ typeof(byte) , "uint8"},
@@ -2946,7 +2948,7 @@ private static string MapAttributesToMof(string[] enumNames, IEnumerable<object>
29462948
if (validateSet != null)
29472949
{
29482950
bool valueMapComma = false;
2949-
StringBuilder sbValues = new StringBuilder(", Values{");
2951+
StringBuilder sbValues = new(", Values{");
29502952
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueMap{{", needComma ? ", " : string.Empty);
29512953
needComma = true;
29522954

@@ -3662,7 +3664,7 @@ public static string GetDSCResourceUsageString(DynamicKeyword keyword)
36623664
private static StringBuilder FormatCimPropertyType(DynamicKeywordProperty prop, bool isOptionalProperty)
36633665
{
36643666
string cimTypeName = prop.TypeConstraint;
3665-
StringBuilder formattedTypeString = new StringBuilder();
3667+
StringBuilder formattedTypeString = new();
36663668

36673669
if (string.Equals(cimTypeName, "MSFT_Credential", StringComparison.OrdinalIgnoreCase))
36683670
{

src/System.Management.Automation/cimSupport/cmdletization/EnumWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ internal static class EnumWriter
1717

1818
private static ModuleBuilder CreateModuleBuilder()
1919
{
20-
AssemblyName aName = new AssemblyName(namespacePrefix);
20+
AssemblyName aName = new(namespacePrefix);
2121
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
2222
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);
2323
return mb;
2424
}
2525

26-
private static Lazy<ModuleBuilder> s_moduleBuilder = new Lazy<ModuleBuilder>(CreateModuleBuilder, isThreadSafe: true);
27-
private static object s_moduleBuilderUsageLock = new object();
26+
private static Lazy<ModuleBuilder> s_moduleBuilder = new(CreateModuleBuilder, isThreadSafe: true);
27+
private static object s_moduleBuilderUsageLock = new();
2828

2929
internal static string GetEnumFullName(EnumMetadataEnum enumMetadata)
3030
{

src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public MethodInvocationInfo(string name, IEnumerable<MethodParameter> parameters
5454

5555
internal IEnumerable<T> GetArgumentsOfType<T>() where T : class
5656
{
57-
List<T> result = new List<T>();
57+
List<T> result = new();
5858
foreach (var methodParameter in this.Parameters)
5959
{
6060
if ((methodParameter.Bindings & MethodParameterBindings.In) != MethodParameterBindings.In)

0 commit comments

Comments
 (0)