Example #1
0
        public override bool IsAssignableFrom(ITypeId type)
        {
            if (type == null || !type.IsResolvable)
            {
                return(false);
            }
            if (this.knownUnreferencedType != KnownUnreferencedType.None)
            {
                IUnreferencedTypeId unreferencedTypeId = type as IUnreferencedTypeId;
                if (unreferencedTypeId != null && unreferencedTypeId.IsKnownUnreferencedType(this.knownUnreferencedType))
                {
                    return(true);
                }
            }
            IType type1 = (IType)type;
            IType type2 = type1.PlatformMetadata.ResolveType(this);

            if (type2.IsResolvable)
            {
                return(type2.IsAssignableFrom(type));
            }
            ProjectContextType projectContextType = type1 as ProjectContextType;

            if (projectContextType != null)
            {
                type2 = projectContextType.TypeResolver.ResolveType(this);
                if (type2 != null)
                {
                    return(type2.IsAssignableFrom(type));
                }
            }
            return(false);
        }
Example #2
0
        public void Initialize(IXmlNamespace xmlNamespace, Type type, string key)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            PlatformTypes platformMetadata = (PlatformTypes)this.PlatformMetadata;

            this.isBuilt      = true;
            this.xmlNamespace = xmlNamespace;
            this.type         = type;
            Type nearestSupportedType = platformMetadata.GetNearestSupportedType(this.type);

            if (nearestSupportedType != null)
            {
                this.nearestSupportedType = platformMetadata.GetType(nearestSupportedType);
            }
            this.lastResolvedType = this.type;
            this.name             = ProjectContextType.GetNameIncludingAnyDeclaringTypes(this.type);
            Assembly  assembly        = this.type.Assembly;
            IAssembly projectAssembly = this.typeResolver.ProjectAssembly;

            if (projectAssembly == null || !projectAssembly.CompareTo(assembly))
            {
                this.assemblyName = AssemblyHelper.GetAssemblyName(assembly).Name;
                if (projectAssembly != null)
                {
                    bool name = this.assemblyName == projectAssembly.Name;
                }
            }
            this.members  = new MemberCollection(this.typeResolver, this);
            this.assembly = this.GetAssembly(this.typeResolver, this.assemblyName);
            if (type.IsArray)
            {
                this.arrayItemType = ProjectContextType.GetItemType(this.typeResolver, type);
                this.arrayRank     = type.GetArrayRank();
            }
            this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.typeResolver, this.type);
            if (this.genericTypeArguments.Count > 0)
            {
                foreach (IType genericTypeArgument in this.genericTypeArguments)
                {
                    ProjectContextType projectContextType = genericTypeArgument as ProjectContextType;
                    if (projectContextType == null)
                    {
                        continue;
                    }
                    this.genericDepth = Math.Max(projectContextType.genericDepth + 1, this.genericDepth);
                }
            }
            this.Cache();
            this.hashCode = key.GetHashCode();
        }
Example #3
0
        private IType GetType(string key, IAssembly assembly, Type type)
        {
            ProjectContextType projectContextType;
            IType type1 = this.platformTypes.GetType(type);

            if (type1 != null)
            {
                return(type1);
            }
            if (assembly == null)
            {
                assembly = this.GetAssembly(type.Assembly);
                if (assembly == null)
                {
                    IAssembly assembly1 = this.platformTypes.CreateAssembly(type.Assembly, AssemblySource.Unknown);
                    foreach (IAssembly assemblyReference in this.AssemblyReferences)
                    {
                        if (!assembly1.Name.StartsWith(assemblyReference.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        string str = assembly1.Name.Substring(assemblyReference.Name.Length);
                        if (string.Compare(str, ".design", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(str, ".expression.design", StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }
                        assembly = assembly1;
                    }
                    if (assembly == null)
                    {
                        return(null);
                    }
                }
            }
            if (key == null)
            {
                key = this.GetKey(assembly, type);
                if (key == null)
                {
                    return(null);
                }
            }
            if (!this.typeIds.TryGetValue(key, out projectContextType))
            {
                projectContextType = new ProjectContextType(this, key);
                this.typeIds.Add(key, projectContextType);
                IXmlNamespace @namespace = this.ProjectNamespaces.GetNamespace(assembly, type);
                projectContextType.Initialize(@namespace, type, key);
            }
            return(projectContextType);
        }
Example #4
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            ITypeId typeId = obj as ITypeId;

            if (typeId == null)
            {
                return(false);
            }
            ProjectContextType projectContextType = this.typeResolver.ResolveType(typeId) as ProjectContextType;

            if (projectContextType == null)
            {
                return(false);
            }
            return(projectContextType.internalName == this.internalName);
        }
Example #5
0
        public IType GetType(string assemblyName, string typeName)
        {
            IAssembly              assembly;
            ProjectContextType     projectContextType;
            UnbuiltTypeDescription unbuiltTypeDescription;
            IType type = null;

            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException(ExceptionStringTable.GetTypeCannotBeCalledWithNullOrEmptyTypeName, "typeName");
            }
            assembly = (!string.IsNullOrEmpty(assemblyName) ? this.GetAssembly(assemblyName) : this.ProjectAssembly);
            if (assembly != null)
            {
                string key = this.GetKey(assembly, typeName);
                if (this.typeIds.TryGetValue(key, out projectContextType))
                {
                    return(projectContextType);
                }
                Type type1 = null;
                try
                {
                    type1 = PlatformTypeHelper.GetType(assembly, typeName);
                }
                catch (Exception exception)
                {
                }
                if (type1 != null)
                {
                    type = this.GetType(key, assembly, type1);
                }
                if (type == null && this.unbuiltTypeInfo.TryGetValue(key, out unbuiltTypeDescription))
                {
                    projectContextType = new ProjectContextType(this, key);
                    this.typeIds.Add(key, projectContextType);
                    projectContextType.Initialize(unbuiltTypeDescription, key);
                    type = projectContextType;
                }
            }
            return(type);
        }
Example #6
0
        private string GetKey(IAssemblyId assembly, Type type)
        {
            string nameIncludingAnyDeclaringTypes = ProjectContextType.GetNameIncludingAnyDeclaringTypes(type);
            string key = this.GetKey(assembly, Microsoft.Expression.DesignModel.Metadata.TypeHelper.CombineNamespaceAndTypeName(type.Namespace, nameIncludingAnyDeclaringTypes));

            if (!type.IsGenericType)
            {
                return(key);
            }
            StringBuilder stringBuilder = new StringBuilder(key);

            stringBuilder.Append('<');
            Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
            if (genericTypeArguments == null)
            {
                return(null);
            }
            for (int i = 0; i < (int)genericTypeArguments.Length; i++)
            {
                Type type1 = genericTypeArguments[i];
                if (i > 0)
                {
                    stringBuilder.Append(',');
                }
                IAssembly assembly1 = this.GetAssembly(type1.Assembly);
                if (assembly1 == null)
                {
                    return(null);
                }
                string str = this.GetKey(assembly1, type1);
                if (str == null)
                {
                    return(null);
                }
                stringBuilder.Append(str);
            }
            stringBuilder.Append('>');
            return(stringBuilder.ToString());
        }
Example #7
0
        public override bool Equals(object obj)
        {
            bool flag;

            if (this == obj)
            {
                return(true);
            }
            ITypeId typeId = obj as ITypeId;

            if (typeId != null && (base.FullName == typeId.FullName || this.MatchesPotentialFullName(typeId.FullName)))
            {
                ProjectContextType projectContextType = typeId as ProjectContextType;
                if (projectContextType == null)
                {
                    return(true);
                }
                IPlatformTypes platformMetadata = (IPlatformTypes)projectContextType.PlatformMetadata;
                using (IEnumerator <IAssemblyId> enumerator = platformMetadata.GetAssemblyGroup(this.AssemblyGroup).GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IAssemblyId current = enumerator.Current;
                        if (projectContextType.RuntimeAssembly.Name != current.Name)
                        {
                            continue;
                        }
                        flag = true;
                        return(flag);
                    }
                    return(false);
                }
                return(flag);
            }
            return(false);
        }
Example #8
0
        public bool Refresh()
        {
            ITypeId     typeId      = this.baseType;
            IPropertyId propertyId  = this.nameProperty;
            IPropertyId propertyId1 = this.defaultContentProperty;
            ITypeId     typeId1     = this.itemType;
            ITypeId     typeId2     = this.nullableType;

            System.ComponentModel.TypeConverter typeConverter = this.typeConverter;
            IAssembly assembly = this.GetAssembly(this.typeResolver, this.assemblyName);

            if (!assembly.IsLoaded)
            {
                return(true);
            }
            this.assembly                = assembly;
            this.type                    = this.GetRuntimeType();
            this.typeConverter           = null;
            this.initializationException = null;
            if (this.type != null)
            {
                this.lastResolvedType = this.type;
                this.isBuilt          = true;
            }
            this.Cache();
            bool flag = true;

            if (this.constructors != null)
            {
                foreach (Constructor constructor in this.constructors)
                {
                    ICachedMemberInfo cachedMemberInfo = constructor;
                    if (cachedMemberInfo == null || cachedMemberInfo.Refresh())
                    {
                        continue;
                    }
                    flag = false;
                }
                if (flag && this.type != null)
                {
                    int num = 0;
                    ConstructorInfo[] constructors = PlatformTypeHelper.GetConstructors(this.type);
                    if (constructors != null)
                    {
                        ConstructorInfo[] constructorInfoArray = constructors;
                        for (int i = 0; i < (int)constructorInfoArray.Length; i++)
                        {
                            if (PlatformTypeHelper.IsAccessibleConstructor(constructorInfoArray[i]))
                            {
                                num++;
                            }
                        }
                    }
                    if (num != this.constructors.Count)
                    {
                        flag = false;
                    }
                }
            }
            if (!this.members.Refresh())
            {
                flag = false;
            }
            if (flag && (typeId != this.baseType || typeId1 != this.itemType || typeId2 != this.nullableType))
            {
                flag = false;
            }
            if (flag && (propertyId != this.nameProperty || propertyId1 != this.defaultContentProperty))
            {
                flag = false;
            }
            if (flag && ProjectContextType.GetTypeConverterId(typeConverter) != ProjectContextType.GetTypeConverterId(this.typeConverter))
            {
                flag = false;
            }
            if (flag && this.constructorArgumentProperties != null)
            {
                IConstructorArgumentProperties constructorArgumentProperties = PlatformTypeHelper.GetConstructorArgumentProperties(this);
                if (constructorArgumentProperties.Count == this.constructorArgumentProperties.Count)
                {
                    foreach (string constructorArgumentProperty in constructorArgumentProperties)
                    {
                        if (constructorArgumentProperties[constructorArgumentProperty] == this.constructorArgumentProperties[constructorArgumentProperty])
                        {
                            continue;
                        }
                        flag = false;
                        break;
                    }
                }
                else
                {
                    flag = false;
                }
            }
            return(flag);
        }
Example #9
0
        private Type GetRuntimeType(ITypeResolver typeResolver, ProjectContextType typeId)
        {
            Type type;

            if (RuntimeGeneratedTypesHelper.IsControlEditingAssembly(typeId.assembly))
            {
                Type sourceType = ControlEditingDesignTypeGenerator.GetSourceType(typeId.RuntimeType);
                if (sourceType != null)
                {
                    ProjectContextType projectContextType = typeResolver.GetType(sourceType) as ProjectContextType;
                    if (projectContextType != null)
                    {
                        Type runtimeType = projectContextType.GetRuntimeType();
                        if (runtimeType != sourceType && runtimeType != null)
                        {
                            Type type1 = (new ControlEditingDesignTypeGenerator(typeResolver)).DefineType(runtimeType);
                            if (type1 != typeId.RuntimeType)
                            {
                                this.assemblyName = AssemblyHelper.GetAssemblyName(type1.Assembly).Name;
                                this.assembly     = this.GetAssembly(this.typeResolver, this.assemblyName);
                                return(type1);
                            }
                        }
                    }
                }
            }
            if (typeId.arrayItemType == null)
            {
                IAssembly runtimeAssembly = typeId.RuntimeAssembly;
                if (runtimeAssembly != null)
                {
                    runtimeAssembly = this.GetAssembly(typeResolver, runtimeAssembly.Name);
                }
                if (runtimeAssembly != null)
                {
                    Type type2 = PlatformTypeHelper.GetType(runtimeAssembly, typeId.FullName);
                    if (type2 != null)
                    {
                        if (!typeId.IsGenericType)
                        {
                            return(type2);
                        }
                        IList <IType> genericTypeArguments = typeId.GetGenericTypeArguments();
                        int           count = genericTypeArguments.Count;
                        if (count > 0)
                        {
                            Type[] typeArray = new Type[count];
                            for (int i = 0; i < count; i++)
                            {
                                Type runtimeType1 = this.GetRuntimeType(genericTypeArguments[i]);
                                if (runtimeType1 == null)
                                {
                                    return(null);
                                }
                                typeArray[i] = runtimeType1;
                            }
                            try
                            {
                                type = type2.MakeGenericType(typeArray);
                            }
                            catch (ArgumentException argumentException)
                            {
                                return(null);
                            }
                            return(type);
                        }
                    }
                }
            }
            else
            {
                Type runtimeType2 = this.GetRuntimeType(typeId.arrayItemType);
                if (runtimeType2 != null)
                {
                    if (typeId.arrayRank <= 1)
                    {
                        return(runtimeType2.MakeArrayType());
                    }
                    return(runtimeType2.MakeArrayType(typeId.arrayRank));
                }
            }
            return(null);
        }
Example #10
0
        private void Cache()
        {
            Type          runtimeType;
            ITypeMetadata metadata;

            if (this.isBuilt)
            {
                this.baseType = null;
                if (this.type != null)
                {
                    Type baseType = this.type.BaseType;
                    if (baseType != null)
                    {
                        this.baseType = this.typeResolver.GetType(baseType);
                    }
                }
                else if (this.lastResolvedType != null && this.lastResolvedType.BaseType != null)
                {
                    this.baseType = this.typeResolver.GetType(this.lastResolvedType.BaseType);
                }
                if (this.baseType == null && !this.IsInterface)
                {
                    this.baseType = this.typeResolver.ResolveType(PlatformTypes.Object);
                }
            }
            if (this.NearestResolvedType != null)
            {
                runtimeType = this.NearestResolvedType.RuntimeType;
            }
            else
            {
                runtimeType = null;
            }
            Type type = runtimeType;

            if (type == null)
            {
                type = typeof(object);
            }
            if (this.typeResolver.MetadataFactory != null)
            {
                metadata = this.typeResolver.MetadataFactory.GetMetadata(type);
            }
            else
            {
                metadata = null;
            }
            this.metadata = metadata;
            if (this.metadata == null || this.genericDepth >= 10)
            {
                this.nameProperty           = null;
                this.defaultContentProperty = null;
            }
            else
            {
                this.nameProperty           = this.metadata.NameProperty;
                this.defaultContentProperty = this.metadata.DefaultContentProperty;
            }
            this.itemType     = ProjectContextType.GetItemType(this.typeResolver, type);
            this.nullableType = null;
            Type nullableType = PlatformTypeHelper.GetNullableType(type);

            if (nullableType != null)
            {
                this.nullableType = this.typeResolver.GetType(nullableType);
            }
            if (this.PlatformMetadata != null)
            {
                this.typeConverter = this.PlatformMetadata.GetTypeConverter(type);
            }
        }