コード例 #1
0
            public bool tryGetSimilarValue(TypeReference type, out T value)
            {
                var key2 = new TypeReferenceKey(type);
                List <TypeReference> list;

                if (!refs.TryGetValue(key2, out list))
                {
                    value = default(T);
                    return(false);
                }

                // Find a type whose version is >= type's version and closest to it.

                TypeReference         foundType    = null;
                var                   typeAsmName  = MemberReferenceHelper.getAssemblyNameReference(type.Scope);
                AssemblyNameReference foundAsmName = null;

                foreach (var otherRef in list)
                {
                    var key = new TypeReferenceSameVersionKey(otherRef);
                    if (!dict.TryGetValue(key, out value))
                    {
                        continue;
                    }

                    if (typeAsmName == null)
                    {
                        foundType = otherRef;
                        break;
                    }

                    var otherAsmName = MemberReferenceHelper.getAssemblyNameReference(otherRef.Scope);
                    if (otherAsmName == null)
                    {
                        continue;
                    }
                    // Check pkt or we could return a type in eg. a SL assembly when it's not a SL app.
                    if (!same(typeAsmName.PublicKeyToken, otherAsmName.PublicKeyToken))
                    {
                        continue;
                    }
                    if (typeAsmName.Version > otherAsmName.Version)
                    {
                        continue;                               // old version
                    }
                    if (foundType == null)
                    {
                        foundAsmName = otherAsmName;
                        foundType    = otherRef;
                        continue;
                    }

                    if (foundAsmName.Version <= otherAsmName.Version)
                    {
                        continue;
                    }
                    foundAsmName = otherAsmName;
                    foundType    = otherRef;
                }

                if (foundType != null)
                {
                    value = dict[new TypeReferenceSameVersionKey(foundType)];
                    return(true);
                }

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