using Microsoft.DotNet.ProjectModel.Compilation; using System.Linq; namespace System.Collections.Generic { public static class CollectionExtensions { public static LibraryAssetGroup GetDefaultGroup(this IEnumerable self) => GetGroup(self, string.Empty); public static LibraryAssetGroup GetRuntimeGroup(this IEnumerable self, string runtime) { if(string.IsNullOrEmpty(runtime)) { throw new ArgumentNullException(nameof(runtime)); } return GetGroup(self, runtime); } private static LibraryAssetGroup GetGroup(IEnumerable groups, string runtime) { return groups.FirstOrDefault(g => g.Runtime == runtime); } public static IEnumerable GetDefaultAssets(this IEnumerable self) => GetAssets(self, string.Empty); public static IEnumerable GetRuntimeAssets(this IEnumerable self, string runtime) { if(string.IsNullOrEmpty(runtime)) { throw new ArgumentNullException(nameof(runtime)); } return GetAssets(self, runtime); } private static IEnumerable GetAssets(IEnumerable self, string runtime) { return self .Where(a => string.Equals(a.Runtime, runtime, StringComparison.Ordinal)) .SelectMany(a => a.Assets); } } }