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 @@ -105,7 +105,7 @@ private PowerShellAssemblyLoadContext(string basePaths)

#region Fields

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

private readonly HashSet<string> _denyListedAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase){
"System.Windows.Forms"
};
private readonly HashSet<string> _denyListedAssemblies =
new(StringComparer.OrdinalIgnoreCase) { "System.Windows.Forms" };

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

#endregion Fields

Expand Down Expand Up @@ -509,7 +508,7 @@ private static Assembly GetTrustedPlatformAssembly(string tpaStrongName)
// it back from the cache of default context.
// - If the requested TPA is not loaded yet, then 'Assembly.Load' will make the
// default context to load it
AssemblyName assemblyName = new AssemblyName(tpaStrongName);
AssemblyName assemblyName = new(tpaStrongName);
Assembly asmLoaded = Assembly.Load(assemblyName);
return asmLoaded;
}
Expand Down
38 changes: 19 additions & 19 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,20 @@ public static bool IsWindowsDesktop
#endif

// format files
internal static readonly List<string> FormatFileNames = new List<string>
{
"Certificate.format.ps1xml",
"Diagnostics.format.ps1xml",
"DotNetTypes.format.ps1xml",
"Event.format.ps1xml",
"FileSystem.format.ps1xml",
"Help.format.ps1xml",
"HelpV3.format.ps1xml",
"PowerShellCore.format.ps1xml",
"PowerShellTrace.format.ps1xml",
"Registry.format.ps1xml",
"WSMan.format.ps1xml"
};
internal static readonly List<string> FormatFileNames = new()
{
"Certificate.format.ps1xml",
"Diagnostics.format.ps1xml",
"DotNetTypes.format.ps1xml",
"Event.format.ps1xml",
"FileSystem.format.ps1xml",
"Help.format.ps1xml",
"HelpV3.format.ps1xml",
"PowerShellCore.format.ps1xml",
"PowerShellTrace.format.ps1xml",
"Registry.format.ps1xml",
"WSMan.format.ps1xml"
};

/// <summary>
/// Some common environment variables used in PS have different
Expand Down Expand Up @@ -566,8 +566,8 @@ internal static int NonWindowsGetProcessParentPid(int pid)
/// <summary>Unix specific implementations of required functionality.</summary>
internal static class Unix
{
private static Dictionary<int, string> usernameCache = new Dictionary<int, string>();
private static Dictionary<int, string> groupnameCache = new Dictionary<int, string>();
private static Dictionary<int, string> usernameCache = new();
private static Dictionary<int, string> groupnameCache = new();

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

// helper for getting unix mode
private Dictionary<StatMask, char> modeMap = new Dictionary<StatMask, char>()
private Dictionary<StatMask, char> modeMap = new()
{
{ StatMask.OwnerRead, CanRead },
{ StatMask.OwnerWrite, CanWrite },
Expand All @@ -726,7 +726,7 @@ public class CommonStat
};

// The item type and the character representation for the first element in the stat string
private Dictionary<ItemType, char> itemTypeTable = new Dictionary<ItemType, char>()
private Dictionary<ItemType, char> itemTypeTable = new()
{
{ ItemType.BlockDevice, 'b' },
{ ItemType.CharacterDevice, 'c' },
Expand Down Expand Up @@ -860,7 +860,7 @@ public static bool IsHardLink(FileSystemInfo fs)
/// <returns>A managed common stat class instance.</returns>
private static CommonStat CopyStatStruct(NativeMethods.CommonStatStruct css)
{
CommonStat cs = new CommonStat();
CommonStat cs = new();
cs.Inode = css.Inode;
cs.Mode = css.Mode;
cs.UserId = css.UserId;
Expand Down
46 changes: 24 additions & 22 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,19 @@ public static class DscClassCache

// Create a list of classes which are not actual DSC resources similar to what we do inside PSDesiredStateConfiguration.psm1
private static readonly string[] s_hiddenResourceList =
{
"MSFT_BaseConfigurationProviderRegistration",
"MSFT_CimConfigurationProviderRegistration",
"MSFT_PSConfigurationProviderRegistration",
};
{
"MSFT_BaseConfigurationProviderRegistration",
"MSFT_CimConfigurationProviderRegistration",
"MSFT_PSConfigurationProviderRegistration",
};

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

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

/// <summary>
/// DSC class cache for this runspace.
Expand Down Expand Up @@ -638,18 +638,20 @@ private static HashSet<string> ScriptKeywordFileCache
/// <summary>
/// Default ModuleName and ModuleVersion to use.
/// </summary>
private static readonly Tuple<string, Version> s_defaultModuleInfoForResource = new Tuple<string, Version>("PSDesiredStateConfiguration", new Version("1.1"));
private static readonly Tuple<string, Version> s_defaultModuleInfoForResource =
new("PSDesiredStateConfiguration", new Version("1.1"));

/// <summary>
/// Default ModuleName and ModuleVersion to use for meta configuration resources.
/// </summary>
internal static readonly Tuple<string, Version> DefaultModuleInfoForMetaConfigResource = new Tuple<string, Version>("PSDesiredStateConfigurationEngine", new Version("2.0"));
internal static readonly Tuple<string, Version> DefaultModuleInfoForMetaConfigResource =
new("PSDesiredStateConfigurationEngine", new Version("2.0"));

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

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

// Load Regular and DSC PS modules
bool importInBoxResourcesImplicitly = false;
List<string> modulePaths = new List<string>();
List<string> modulePaths = new();
if (modulePathList == null || modulePathList.Count == 0)
{
modulePaths.Add(Path.Combine(configSystemPath, inboxModulePath));
Expand Down Expand Up @@ -1131,7 +1133,7 @@ private static List<DscClassCacheEntry> GetCachedClasses()
/// <returns>List of cached cim classes.</returns>
public static List<Microsoft.Management.Infrastructure.CimClass> GetCachedClassesForModule(PSModuleInfo module)
{
List<Microsoft.Management.Infrastructure.CimClass> cachedClasses = new List<Microsoft.Management.Infrastructure.CimClass>();
List<Microsoft.Management.Infrastructure.CimClass> cachedClasses = new();
var moduleQualifiedName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", module.Name, module.Version.ToString());
foreach (var dscClassCacheEntry in ClassCache)
{
Expand All @@ -1151,7 +1153,7 @@ private static List<DscClassCacheEntry> GetCachedClasses()
/// <returns></returns>
public static List<string> GetFileDefiningClass(string className)
{
List<string> files = new List<string>();
List<string> files = new();
foreach (var pair in ByFileClassCache)
{
var file = pair.Key;
Expand Down Expand Up @@ -1298,7 +1300,7 @@ private static string GetFriendlyName(CimClass cimClass)
/// </summary>
public static Collection<DynamicKeyword> GetCachedKeywords()
{
Collection<DynamicKeyword> keywords = new Collection<DynamicKeyword>();
Collection<DynamicKeyword> keywords = new();

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

ProcessMembers(sb, embeddedInstanceTypes, typeAst, className);

Queue<object> bases = new Queue<object>();
Queue<object> bases = new();
foreach (var b in typeAst.BaseTypes)
{
bases.Enqueue(b);
Expand Down Expand Up @@ -2459,7 +2461,7 @@ public static bool GetResourceMethodsLinePosition(PSModuleInfo moduleInfo, strin
}

IEnumerable<Ast> resourceDefinitions;
List<string> moduleFiles = new List<string>();
List<string> moduleFiles = new();
if (moduleInfo.RootModule != null)
{
moduleFiles.Add(moduleInfo.Path);
Expand Down Expand Up @@ -2593,7 +2595,7 @@ private static bool GetResourceDefinitionsFromModule(string fileName, out IEnume
{
if (errorList != null && extent != null)
{
List<string> errorMessages = new List<string>();
List<string> errorMessages = new();
foreach (var error in errors)
{
errorMessages.Add(error.ToString());
Expand Down Expand Up @@ -2698,7 +2700,7 @@ private static bool ImportKeywordsFromScriptFile(string fileName, PSModuleInfo m
return result;
}

private static readonly Dictionary<Type, string> s_mapPrimitiveDotNetTypeToMof = new Dictionary<Type, string>()
private static readonly Dictionary<Type, string> s_mapPrimitiveDotNetTypeToMof = new()
{
{ typeof(sbyte), "sint8" },
{ typeof(byte) , "uint8"},
Expand Down Expand Up @@ -2946,7 +2948,7 @@ private static string MapAttributesToMof(string[] enumNames, IEnumerable<object>
if (validateSet != null)
{
bool valueMapComma = false;
StringBuilder sbValues = new StringBuilder(", Values{");
StringBuilder sbValues = new(", Values{");
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueMap{{", needComma ? ", " : string.Empty);
needComma = true;

Expand Down Expand Up @@ -3662,7 +3664,7 @@ public static string GetDSCResourceUsageString(DynamicKeyword keyword)
private static StringBuilder FormatCimPropertyType(DynamicKeywordProperty prop, bool isOptionalProperty)
{
string cimTypeName = prop.TypeConstraint;
StringBuilder formattedTypeString = new StringBuilder();
StringBuilder formattedTypeString = new();

if (string.Equals(cimTypeName, "MSFT_Credential", StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ internal static class EnumWriter

private static ModuleBuilder CreateModuleBuilder()
{
AssemblyName aName = new AssemblyName(namespacePrefix);
AssemblyName aName = new(namespacePrefix);
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);
return mb;
}

private static Lazy<ModuleBuilder> s_moduleBuilder = new Lazy<ModuleBuilder>(CreateModuleBuilder, isThreadSafe: true);
private static object s_moduleBuilderUsageLock = new object();
private static Lazy<ModuleBuilder> s_moduleBuilder = new(CreateModuleBuilder, isThreadSafe: true);
private static object s_moduleBuilderUsageLock = new();

internal static string GetEnumFullName(EnumMetadataEnum enumMetadata)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MethodInvocationInfo(string name, IEnumerable<MethodParameter> parameters

internal IEnumerable<T> GetArgumentsOfType<T>() where T : class
{
List<T> result = new List<T>();
List<T> result = new();
foreach (var methodParameter in this.Parameters)
{
if ((methodParameter.Bindings & MethodParameterBindings.In) != MethodParameterBindings.In)
Expand Down
Loading