Example #1
0
            public T this[TypeReference type] {
                get {
                    T value;
                    if (tryGetValue(type, out value))
                    {
                        return(value);
                    }
                    throw new KeyNotFoundException();
                }
                set {
                    var key = new TypeReferenceSameVersionKey(type);
                    dict[key] = value;

                    if (value != null)
                    {
                        var key2 = new TypeReferenceKey(type);
                        List <TypeReference> list;
                        if (!refs.TryGetValue(key2, out list))
                        {
                            refs[key2] = list = new List <TypeReference>();
                        }
                        list.Add(type);
                    }
                }
            }
Example #2
0
        public void addInterface(TypeInfo iface)
        {
            var key = new TypeReferenceKey(iface.typeReference);

            if (!interfaceMethods.ContainsKey(key))
            {
                interfaceMethods[key] = new InterfaceMethodInfo(iface);
            }
        }
Example #3
0
        public void addMethodIfEmpty(TypeInfo iface, MethodDef ifaceMethod, MethodDef classMethod)
        {
            InterfaceMethodInfo info;
            var key = new TypeReferenceKey(iface.typeReference);

            if (!interfaceMethods.TryGetValue(key, out info))
            {
                throw new ApplicationException("Could not find interface");
            }
            info.addMethodIfEmpty(ifaceMethod, classMethod);
        }
Example #4
0
        // Returns the previous classMethod, or null if none
        public MethodDef addMethod(TypeReference iface, MethodDef ifaceMethod, MethodDef classMethod)
        {
            InterfaceMethodInfo info;
            var key = new TypeReferenceKey(iface);

            if (!interfaceMethods.TryGetValue(key, out info))
            {
                throw new ApplicationException("Could not find interface");
            }
            return(info.addMethod(ifaceMethod, classMethod));
        }
Example #5
0
        TypeInstanceResolver getTypeInstance(TypeReference typeReference)
        {
            var key = new TypeReferenceKey(typeReference);
            TypeInstanceResolver instance;

            if (!typeRefToInstance.TryGetValue(key, out instance))
            {
                typeRefToInstance[key] = instance = new TypeInstanceResolver(type, typeReference);
            }
            return(instance);
        }
Example #6
0
        TypeReference add(bool isValueType, TypeReference typeRef)
        {
            var           key = new TypeReferenceKey(typeRef);
            TypeReference createdTypeRef;

            if (createdTypes.TryGetValue(key, out createdTypeRef))
            {
                if (createdTypeRef.IsValueType != isValueType)
                {
                    throw new ApplicationException(string.Format("Type {0}'s IsValueType is not correct", createdTypeRef));
                }
                return(createdTypeRef);
            }
            createdTypes[key] = typeRef;
            return(typeRef);
        }
Example #7
0
        public void initializeFrom(InterfaceMethodInfos other, GenericInstanceType git)
        {
            foreach (var pair in other.interfaceMethods)
            {
                var oldTypeInfo = pair.Value.IFace;
                var newTypeInfo = new TypeInfo(oldTypeInfo, git);
                var oldKey      = new TypeReferenceKey(oldTypeInfo.typeReference);
                var newKey      = new TypeReferenceKey(newTypeInfo.typeReference);

                InterfaceMethodInfo newMethodsInfo = new InterfaceMethodInfo(newTypeInfo, other.interfaceMethods[oldKey]);
                if (interfaceMethods.ContainsKey(newKey))
                {
                    newMethodsInfo.merge(interfaceMethods[newKey]);
                }
                interfaceMethods[newKey] = newMethodsInfo;
            }
        }
Example #8
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);
            }