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 @@ -66,8 +66,8 @@ private IEnumerable<MethodParameter> GetMethodInputParametersCore(Func<MethodPar

internal IEnumerable<MethodParameter> GetMethodInputParameters()
{
var allMethodParameters = this.GetMethodInputParametersCore(p => !p.Name.StartsWith(CustomOperationOptionPrefix, StringComparison.OrdinalIgnoreCase));
var methodParametersWithInputValue = allMethodParameters.Where(p => p.IsValuePresent);
var allMethodParameters = this.GetMethodInputParametersCore(static p => !p.Name.StartsWith(CustomOperationOptionPrefix, StringComparison.OrdinalIgnoreCase));
var methodParametersWithInputValue = allMethodParameters.Where(static p => p.IsValuePresent);
return methodParametersWithInputValue;
}

Expand All @@ -81,7 +81,7 @@ internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
IDictionary<string, object> result = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

IEnumerable<MethodParameter> customOptions = this
.GetMethodInputParametersCore(p => p.Name.StartsWith(CustomOperationOptionPrefix, StringComparison.OrdinalIgnoreCase));
.GetMethodInputParametersCore(static p => p.Name.StartsWith(CustomOperationOptionPrefix, StringComparison.OrdinalIgnoreCase));
foreach (MethodParameter customOption in customOptions)
{
if (customOption.Value == null)
Expand All @@ -104,7 +104,7 @@ internal IEnumerable<MethodParameter> GetMethodOutputParameters()
}

var outParameters = allParameters_plus_returnValue
.Where(p => ((p.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)) != 0));
.Where(static p => ((p.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)) != 0));

return outParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private static string GetMatchCondition(string propertyName, IEnumerable propert
.Select(propertyValue => wildcardsEnabled
? GetMatchConditionForLikeOperator(propertyName, propertyValue)
: GetMatchConditionForEqualityOperator(propertyName, propertyValue))
.Where(individualCondition => !string.IsNullOrWhiteSpace(individualCondition))
.Where(static individualCondition => !string.IsNullOrWhiteSpace(individualCondition))
.ToList();
if (individualConditions.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public override bool ShouldReportErrorOnNoMatches_IfMultipleFilters()
case BehaviorOnNoMatch.Default:
default:
return this.PropertyValueFilters
.Any(f => !f.HadMatch && f.BehaviorOnNoMatch == BehaviorOnNoMatch.ReportErrors);
.Any(static f => !f.HadMatch && f.BehaviorOnNoMatch == BehaviorOnNoMatch.ReportErrors);
}
}

Expand Down Expand Up @@ -656,7 +656,7 @@ internal IEnumerable<NotFoundError> GenerateNotFoundErrors()
return Enumerable.Empty<NotFoundError>();
}

if (_filters.All(f => !f.ShouldReportErrorOnNoMatches_IfMultipleFilters()))
if (_filters.All(static f => !f.ShouldReportErrorOnNoMatches_IfMultipleFilters()))
{
return Enumerable.Empty<NotFoundError>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ internal List<ServiceController> DoStopService(ServiceController serviceControll
/// </returns>
private static bool HaveAllDependentServicesStopped(ServiceController[] dependentServices)
{
return Array.TrueForAll(dependentServices, service => service.Status == ServiceControllerStatus.Stopped);
return Array.TrueForAll(dependentServices, static service => service.Status == ServiceControllerStatus.Stopped);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static Dictionary<string, List<string>> GetTypeGroupMap(IEnumerable<Type
// first type group will take effect. So we skip the rest groups that have the same name.
if (!typeGroupMap.ContainsKey(typeGroup.name))
{
var typesInGroup = typeGroup.typeReferenceList.Select(typeReference => typeReference.name).ToList();
var typesInGroup = typeGroup.typeReferenceList.Select(static typeReference => typeReference.name).ToList();
typeGroupMap.Add(typeGroup.name, typesInGroup);
}
}
Expand All @@ -98,7 +98,7 @@ private static Dictionary<string, List<string>> GetTypeGroupMap(IEnumerable<Type
/// </summary>
protected override void ProcessRecord()
{
// Remoting detection:
// Remoting detection:
// * Automatic variable $PSSenderInfo is defined in true remoting contexts as well as in background jobs.
// * $PSSenderInfo.ApplicationArguments.PSVersionTable.PSVersion contains the client version, as a [version] instance.
// Note: Even though $PSVersionTable.PSVersion is of type [semver] in PowerShell 6+, it is of type [version] here,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected override void ProcessRecord()
breakpoints = Filter(
breakpoints,
Id,
(Breakpoint breakpoint, int id) => breakpoint.Id == id);
static (Breakpoint breakpoint, int id) => breakpoint.Id == id);
}
else if (ParameterSetName.Equals(CommandParameterSetName, StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void WriteMatches(string value, string parametersetname)
}

results.Sort(
(AliasInfo left, AliasInfo right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));
static (AliasInfo left, AliasInfo right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));
foreach (AliasInfo alias in results)
{
this.WriteObject(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private void UpdateOrderPropertyTypeInfo(List<ObjectCommandPropertyValue> curren
{
if (_propertyTypesCandidate == null)
{
_propertyTypesCandidate = currentEntryOrderValues.Select(c => PSObject.Base(c.PropertyValue)?.GetType()).ToArray();
_propertyTypesCandidate = currentEntryOrderValues.Select(static c => PSObject.Base(c.PropertyValue)?.GetType()).ToArray();
return;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ protected override void EndProcessing()
{
// using OrderBy to get stable sort.
// fast path when we only have the same object types to group
foreach (var entry in _entriesToOrder.OrderBy(e => e, _orderByPropertyComparer))
foreach (var entry in _entriesToOrder.OrderBy(static e => e, _orderByPropertyComparer))
{
DoOrderedGrouping(entry, NoElement, _groups, _tupleToGroupInfoMappingDictionary, _orderByPropertyComparer);
if (Stopping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override void ProcessRecord()
}
else
{
var data = ast.Find(a => a is HashtableAst, false);
var data = ast.Find(static a => a is HashtableAst, false);
if (data != null)
{
WriteObject(data.SafeGetValue(SkipLimitCheck));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ShowCommandCommandInfo(CommandInfo other)
{
this.ParameterSets =
other.ParameterSets
.Select(x => new ShowCommandParameterSetInfo(x))
.Select(static x => new ShowCommandParameterSetInfo(x))
.ToList()
.AsReadOnly();
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public ShowCommandCommandInfo(PSObject other)
this.CommandType = (CommandTypes)((other.Members["CommandType"].Value as PSObject).BaseObject);

var parameterSets = (other.Members["ParameterSets"].Value as PSObject).BaseObject as System.Collections.ArrayList;
this.ParameterSets = GetObjectEnumerable(parameterSets).Cast<PSObject>().Select(x => new ShowCommandParameterSetInfo(x)).ToList().AsReadOnly();
this.ParameterSets = GetObjectEnumerable(parameterSets).Cast<PSObject>().Select(static x => new ShowCommandParameterSetInfo(x)).ToList().AsReadOnly();

if (other.Members["Module"]?.Value is PSObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ShowCommandParameterInfo(CommandParameterInfo other)
this.ParameterType = new ShowCommandParameterType(other.ParameterType);
this.Position = other.Position;

var validateSetAttribute = other.Attributes.Where(x => typeof(ValidateSetAttribute).IsAssignableFrom(x.GetType())).Cast<ValidateSetAttribute>().LastOrDefault();
var validateSetAttribute = other.Attributes.Where(static x => typeof(ValidateSetAttribute).IsAssignableFrom(x.GetType())).Cast<ValidateSetAttribute>().LastOrDefault();
if (validateSetAttribute != null)
{
this.HasParameterSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ShowCommandParameterSetInfo(CommandParameterSetInfo other)

this.Name = other.Name;
this.IsDefault = other.IsDefault;
this.Parameters = other.Parameters.Select(x => new ShowCommandParameterInfo(x)).ToArray();
this.Parameters = other.Parameters.Select(static x => new ShowCommandParameterInfo(x)).ToArray();
}

/// <summary>
Expand All @@ -49,7 +49,7 @@ public ShowCommandParameterSetInfo(PSObject other)
this.Name = other.Members["Name"].Value as string;
this.IsDefault = (bool)(other.Members["IsDefault"].Value);
var parameters = (other.Members["Parameters"].Value as PSObject).BaseObject as System.Collections.ArrayList;
this.Parameters = ShowCommandCommandInfo.GetObjectEnumerable(parameters).Cast<PSObject>().Select(x => new ShowCommandParameterInfo(x)).ToArray();
this.Parameters = ShowCommandCommandInfo.GetObjectEnumerable(parameters).Cast<PSObject>().Select(static x => new ShowCommandParameterInfo(x)).ToArray();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected override void ProcessRecord()
GetMatchingVariables(varName, Scope, out wasFiltered, /*quiet*/ false);

matchingVariables.Sort(
(PSVariable left, PSVariable right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));
static (PSVariable left, PSVariable right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));

bool matchFound = false;
foreach (PSVariable matchingVariable in matchingVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public string[] Name
protected override void ProcessRecord()
{
var sources = GetMatchingTraceSource(_names, true);
var result = sources.OrderBy(source => source.Name);
var result = sources.OrderBy(static source => source.Name);
WriteObject(result, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,7 @@ private class ConsoleHostStartupException : Exception
private bool _isDisposed;
internal ConsoleHostUserInterface ui;

internal Lazy<TextReader> ConsoleIn { get; } = new Lazy<TextReader>(() => Console.In);
internal Lazy<TextReader> ConsoleIn { get; } = new Lazy<TextReader>(static () => Console.In);

private string _savedWindowTitle = string.Empty;
private readonly Version _ver = PSVersionInfo.PSVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private IEnumerable<LocalPrincipal> ProcessesMembership(IEnumerable<LocalPrincip
}

// sort the resulting principals by mane
rv.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.CurrentCultureIgnoreCase));
rv.Sort(static (p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.CurrentCultureIgnoreCase));

return rv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private static bool FindInGac(string gacRoot, AssemblyName assemblyName, out str
if (Directory.Exists(tempAssemblyDirPath))
{
// Enumerate all directories, sort by name and select the last. This selects the latest version.
var chosenVersionDirectory = Directory.EnumerateDirectories(tempAssemblyDirPath).OrderBy(d => d).LastOrDefault();
var chosenVersionDirectory = Directory.EnumerateDirectories(tempAssemblyDirPath).OrderBy(static d => d).LastOrDefault();

if (!string.IsNullOrEmpty(chosenVersionDirectory))
{
Expand Down
20 changes: 10 additions & 10 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public static void Initialize(Collection<Exception> errors, List<string> moduleP
continue;
}

foreach (var schemaFile in Directory.EnumerateDirectories(resources).SelectMany(d => Directory.EnumerateFiles(d, "*.schema.mof")))
foreach (var schemaFile in Directory.EnumerateDirectories(resources).SelectMany(static d => Directory.EnumerateFiles(d, "*.schema.mof")))
{
ImportClasses(schemaFile, s_defaultModuleInfoForResource, errors);
}
Expand Down Expand Up @@ -776,7 +776,7 @@ public static void Initialize(Collection<Exception> errors, List<string> moduleP
continue;
}

foreach (var schemaFile in Directory.EnumerateDirectories(resources).SelectMany(d => Directory.EnumerateFiles(d, "*.schema.mof")))
foreach (var schemaFile in Directory.EnumerateDirectories(resources).SelectMany(static d => Directory.EnumerateFiles(d, "*.schema.mof")))
{
ImportClasses(schemaFile, s_defaultModuleInfoForResource, errors);
}
Expand Down Expand Up @@ -2344,7 +2344,7 @@ internal static string MapTypeNameToMofType(ITypeName typeName, string memberNam

if (propTypeName._typeDefinitionAst.IsEnum)
{
enumNames = propTypeName._typeDefinitionAst.Members.Select(m => m.Name).ToArray();
enumNames = propTypeName._typeDefinitionAst.Members.Select(static m => m.Name).ToArray();
isArrayType = false;
embeddedInstanceType = null;
return "string";
Expand All @@ -2366,7 +2366,7 @@ private static void GenerateMofForAst(TypeDefinitionAst typeAst, StringBuilder s
var className = typeAst.Name;
sb.AppendFormat(CultureInfo.InvariantCulture, "[ClassVersion(\"1.0.0\"), FriendlyName(\"{0}\")]\nclass {0}", className);

if (typeAst.Attributes.Any(a => a.TypeName.GetReflectionAttributeType() == typeof(DscResourceAttribute)))
if (typeAst.Attributes.Any(static a => a.TypeName.GetReflectionAttributeType() == typeof(DscResourceAttribute)))
{
sb.Append(" : OMI_BaseResource");
}
Expand Down Expand Up @@ -2481,7 +2481,7 @@ public static bool GetResourceMethodsLinePosition(PSModuleInfo moduleInfo, strin

if (moduleInfo.NestedModules != null)
{
foreach (var nestedModule in moduleInfo.NestedModules.Where(m => !string.IsNullOrEmpty(m.Path)))
foreach (var nestedModule in moduleInfo.NestedModules.Where(static m => !string.IsNullOrEmpty(m.Path)))
{
moduleFiles.Add(nestedModule.Path);
}
Expand Down Expand Up @@ -3087,9 +3087,9 @@ private static void GenerateMofForType(Type type, StringBuilder sb, List<object>

private static void ProcessMembers(Type type, StringBuilder sb, List<object> embeddedInstanceTypes, string className)
{
foreach (var member in type.GetMembers(BindingFlags.Instance | BindingFlags.Public).Where(m => m is PropertyInfo || m is FieldInfo))
foreach (var member in type.GetMembers(BindingFlags.Instance | BindingFlags.Public).Where(static m => m is PropertyInfo || m is FieldInfo))
{
if (member.CustomAttributes.All(cad => cad.AttributeType != typeof(DscPropertyAttribute)))
if (member.CustomAttributes.All(static cad => cad.AttributeType != typeof(DscPropertyAttribute)))
{
continue;
}
Expand Down Expand Up @@ -3141,7 +3141,7 @@ private static bool ImportKeywordsFromAssembly(PSModuleInfo module,
var parser = new Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser(MyClassCallback);

IEnumerable<Type> resourceDefinitions =
assembly.GetTypes().Where(t => t.GetCustomAttributes<DscResourceAttribute>().Any());
assembly.GetTypes().Where(static t => t.GetCustomAttributes<DscResourceAttribute>().Any());

foreach (var r in resourceDefinitions)
{
Expand Down Expand Up @@ -3635,7 +3635,7 @@ public static string GetDSCResourceUsageString(DynamicKeyword keyword)
bool listKeyProperties = true;
while (true)
{
foreach (var prop in keyword.Properties.OrderBy(ob => ob.Key))
foreach (var prop in keyword.Properties.OrderBy(static ob => ob.Key))
{
if (string.Equals(prop.Key, "ResourceId", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -3702,7 +3702,7 @@ private static StringBuilder FormatCimPropertyType(DynamicKeywordProperty prop,
// Do the property values map
if (prop.ValueMap != null && prop.ValueMap.Count > 0)
{
formattedTypeString.Append(" { " + string.Join(" | ", prop.ValueMap.Keys.OrderBy(x => x)) + " }");
formattedTypeString.Append(" { " + string.Join(" | ", prop.ValueMap.Keys.OrderBy(static x => x)) + " }");
}

// We prepend optional property with "[" so close out it here. This way it is shown with [ ] to indication optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static void Initialize(Collection<Exception> errors, List<string> moduleP
});

if (moduleInfos.Count > 0)
{
{
// to be consistent with Import-Module behavior, we use the first occurrence that we find in PSModulePath
var moduleDirectory = Path.GetDirectoryName(moduleInfos[0].Path);
dscConfigurationDirectory = Path.Join(moduleDirectory, "Configuration");
Expand Down Expand Up @@ -760,7 +760,7 @@ private static void LoadDefaultCimKeywords(
errors.Add(exception);
return;
}

NewApiIsUsed = true;
DynamicKeyword.Reset();
Initialize(errors, modulePathList);
Expand Down Expand Up @@ -1294,7 +1294,7 @@ private static List<PSObject> ProcessEmbeddedInstanceTypes(List<object> embedded

return result;
}

private static void AddEmbeddedInstanceTypesToCaches(IEnumerable<PSObject> classes, PSModuleInfo module, DSCResourceRunAsCredential runAsBehavior)
{
foreach (dynamic c in classes)
Expand Down Expand Up @@ -1540,7 +1540,7 @@ private static bool GetResourceDefinitionsFromModule(string fileName, out IEnume
{
errorMessages.Add(error.ToString());
}

PSInvalidOperationException e = PSTraceSource.NewInvalidOperationException(ParserStrings.FailToParseModuleScriptFile, fileName, string.Join(Environment.NewLine, errorMessages));
e.SetErrorId("FailToParseModuleScriptFile");
errorList.Add(e);
Expand Down
Loading