Exemplo n.º 1
0
        public bool TryGetValue(AssemblyIdentity identity, out TValue value, bool allowHigherVersion = true)
        {
            OneOrMany <KeyValuePair <AssemblyIdentity, TValue> > sameName;

            if (_map.TryGetValue(identity.Name, out sameName))
            {
                int minHigherVersionCandidate = -1;

                for (int i = 0; i < sameName.Count; i++)
                {
                    AssemblyIdentity currentIdentity = sameName[i].Key;

                    if (AssemblyIdentity.EqualIgnoringNameAndVersion(currentIdentity, identity))
                    {
                        if (currentIdentity.Version == identity.Version)
                        {
                            value = sameName[i].Value;
                            return(true);
                        }

                        // only higher version candidates are considered for match:
                        if (!allowHigherVersion || currentIdentity.Version < identity.Version)
                        {
                            continue;
                        }

                        if (minHigherVersionCandidate == -1 || currentIdentity.Version < sameName[minHigherVersionCandidate].Key.Version)
                        {
                            minHigherVersionCandidate = i;
                        }
                    }
                }

                if (minHigherVersionCandidate >= 0)
                {
                    value = sameName[minHigherVersionCandidate].Value;
                    return(true);
                }
            }

            value = default(TValue);
            return(false);
        }
Exemplo n.º 2
0
        public bool TryGetValue(AssemblyIdentity identity, out TValue value, Func <Version, Version, TValue, bool> comparer)
        {
            OneOrMany <KeyValuePair <AssemblyIdentity, TValue> > sameName;

            if (_map.TryGetValue(identity.Name, out sameName))
            {
                for (int i = 0; i < sameName.Count; i++)
                {
                    AssemblyIdentity currentIdentity = sameName[i].Key;

                    if (comparer(identity.Version, currentIdentity.Version, sameName[i].Value) &&
                        AssemblyIdentity.EqualIgnoringNameAndVersion(currentIdentity, identity))
                    {
                        value = sameName[i].Value;
                        return(true);
                    }
                }
            }

            value = default(TValue);
            return(false);
        }