Skip to content

Commit

Permalink
Merge pull request #226 from Lombiq/issue/OSOE-713
Browse files Browse the repository at this point in the history
OSOE-713: Adjust SingleResourceTypeToLookup to not crash when a resource is defined without any dependencies.
  • Loading branch information
Piedone authored Dec 7, 2023
2 parents 9346c1c + 67e01d6 commit 69880f2
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 69880f2

Please sign in to comment.