Beispiel #1
0
        /// <summary>
        /// Finds all expansions using the mapping provider
        /// </summary>
        private IEnumerable<NuGetFramework> ExpandInternal(NuGetFramework framework)
        {
            // check the framework directly, this includes profiles which the range doesn't return
            IEnumerable<NuGetFramework> directlyEquivalent = null;
            if (_mappings.TryGetEquivalentFrameworks(framework, out directlyEquivalent))
            {
                foreach (var eqFw in directlyEquivalent)
                {
                    yield return eqFw;
                }
            }

            // 0.0 through the current framework
            var frameworkRange = new FrameworkRange(
                new NuGetFramework(framework.Framework, new Version(0, 0), framework.Profile),
                framework);

            IEnumerable<NuGetFramework> equivalent = null;
            if (_mappings.TryGetEquivalentFrameworks(frameworkRange, out equivalent))
            {
                foreach (var eqFw in equivalent)
                {
                    yield return eqFw;
                }
            }

            // find all possible sub set frameworks if no profile is used
            if (!framework.HasProfile)
            {
                IEnumerable<string> subSetFrameworks = null;
                if (_mappings.TryGetSubSetFrameworks(framework.Framework, out subSetFrameworks))
                {
                    foreach (var subFramework in subSetFrameworks)
                    {
                        // clone the framework but use the sub framework instead
                        yield return new NuGetFramework(subFramework, framework.Version, framework.Profile);
                    }
                }
            }

            // explicit compatiblity mappings
            IEnumerable<FrameworkRange> ranges = null;
            if (_mappings.TryGetCompatibilityMappings(framework, out ranges))
            {
                foreach (var range in ranges)
                {
                    yield return range.Min;

                    if (!range.Min.Equals(range.Max))
                    {
                        yield return range.Max;
                    }
                }
            }

            yield break;
        }
        public bool TryGetEquivalentFrameworks(FrameworkRange range, out IEnumerable<NuGetFramework> frameworks)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            var relevant = new HashSet<NuGetFramework>(NuGetFramework.Comparer);

            foreach (var framework in _equivalentFrameworks.Keys.Where(f => range.Satisfies(f)))
            {
                relevant.Add(framework);
            }

            var results = new HashSet<NuGetFramework>(NuGetFramework.Comparer);

            foreach (var framework in relevant)
            {
                IEnumerable<NuGetFramework> values = null;
                if (TryGetEquivalentFrameworks(framework, out values))
                {
                    foreach (var val in values)
                    {
                        results.Add(val);
                    }
                }
            }

            frameworks = results;
            return results.Count > 0;
        }