Skip to content

Commit

Permalink
Adjust SingleResourceTypeToLookup to not crash when a resource is def…
Browse files Browse the repository at this point in the history
…ined without any dependencies.
  • Loading branch information
sarahelsaig committed Dec 6, 2023
1 parent 9346c1c commit 67e01d6
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ void Add(IEnumerable<ResourceDefinition> additionalDependencies)

/// <summary>
/// Gets all resource dictionaries of a given <paramref name="resourceType"/> and collapses them into a lookup where
/// the key is the resource name and the values are the dependencies.
/// the key is the resource name and the values are the dependencies. Resource definitions with no dependencies are
/// skipped.
/// </summary>
public static ILookup<string, string> SingleResourceTypeToLookup(
this IEnumerable<ResourceManifest> resourceManifest,
string resourceType) =>
resourceManifest
.SelectMany(manifest => manifest.GetResources(resourceType))
.SelectMany(pair => pair.Value.SelectMany(definition =>
definition.Dependencies.Select(dependency => new { Resource = pair.Key, Dependency = dependency })))
.Where(pair => pair.Value != null)
.SelectMany(pair => pair.Value
.SelectWhere(definition => definition?.Dependencies, dependencies => dependencies?.Any() == true)
.SelectMany(dependencies => dependencies
.Select(dependency => new { Resource = pair.Key, Dependency = dependency })))
.ToLookup(pair => pair.Resource, pair => pair.Dependency);
}

0 comments on commit 67e01d6

Please sign in to comment.