public IType GetType(Type type)
        {
            if (type == (Type)null)
            {
                return((IType)null);
            }
            IType type1;

            if (this.typeCache.TryGetValue(type, out type1))
            {
                return(type1);
            }
            DesignTypeResult designType = this.Generator.GetDesignType(type);

            if (designType.IsFailed)
            {
                return(this.actualProjectContext.GetType(type));
            }
            IType type2 = this.actualProjectContext.GetType(designType.SourceType);

            if (designType.SourceType == designType.DesignType)
            {
                return(type2);
            }
            type1 = (IType) new TypeReflectingProjectContext.DesignType(this.actualProjectContext.GetType(designType.DesignType), type2, (ITypeResolver)this);
            this.typeCache[designType.SourceType] = type1;
            this.typeCache[designType.DesignType] = type1;
            return(type1);
        }
示例#2
0
        private static IType GetDesignInstanceType(DocumentCompositeNode designInstanceNode)
        {
            if (designInstanceNode.DocumentRoot == null)
            {
                return((IType)null);
            }
            IType        type      = (IType)null;
            IProperty    property1 = (IProperty)designInstanceNode.Type.GetMember(MemberType.LocalProperty, "Type", MemberAccessTypes.Public);
            DocumentNode dataNode  = designInstanceNode.Properties[(IPropertyId)property1];

            if (dataNode != null)
            {
                IType dataType = DataContextHelper.GetDataType(dataNode);
                if (dataType.RuntimeType == (Type)null)
                {
                    return((IType)null);
                }
                IProperty             property2 = (IProperty)designInstanceNode.Type.GetMember(MemberType.LocalProperty, "CreateList", MemberAccessTypes.Public);
                DocumentPrimitiveNode documentPrimitiveNode1 = designInstanceNode.Properties[(IPropertyId)property2] as DocumentPrimitiveNode;
                bool                  createList             = documentPrimitiveNode1 != null && documentPrimitiveNode1.GetValue <bool>();
                IProperty             property3 = (IProperty)designInstanceNode.Type.GetMember(MemberType.LocalProperty, "IsDesignTimeCreatable", MemberAccessTypes.Public);
                DocumentPrimitiveNode documentPrimitiveNode2 = designInstanceNode.Properties[(IPropertyId)property3] as DocumentPrimitiveNode;
                bool                  isDesignTimeCreatable  = documentPrimitiveNode2 != null && documentPrimitiveNode2.GetValue <bool>();
                DesignTypeResult      typeToInstantiate      = DesignTypeInstanceBuilder.GetTypeToInstantiate(designInstanceNode.PlatformMetadata, dataType.RuntimeType, createList, isDesignTimeCreatable);
                if (typeToInstantiate.IsFailed)
                {
                    return((IType)null);
                }
                type = designInstanceNode.TypeResolver.GetType(typeToInstantiate.DesignType);
            }
            return(type);
        }
示例#3
0
        public static IType GetSourceType(IType type, ITypeResolver typeResolver)
        {
            if (typeResolver.PlatformMetadata.IsNullType((ITypeId)type))
            {
                return(type);
            }
            DesignTypeResult designTypeResult = DesignTypeGenerator.LookupGetDesignTypeResult(type.RuntimeType);

            if (designTypeResult != null && !designTypeResult.IsFailed && designTypeResult.SourceType != type.RuntimeType)
            {
                ITypeResolver typeResolver1 = (ITypeResolver)ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext) ?? typeResolver;
                IType         type1         = typeResolver1.GetType(designTypeResult.SourceType);
                if (!typeResolver1.PlatformMetadata.IsNullType((ITypeId)type1))
                {
                    return(type1);
                }
            }
            return(type);
        }
        public static DesignTypeResult GetTypeToInstantiate(IPlatformMetadata platformMetadata, Type sourceType, bool createList, bool isDesignTimeCreatable)
        {
            Type designType = sourceType;
            DesignTypeGenerator designTypeGenerator = new DesignTypeGenerator(platformMetadata);

            if (!isDesignTimeCreatable)
            {
                DesignTypeResult designTypeResult = designTypeGenerator.GetDesignType(sourceType);
                if (designTypeResult.IsFailed)
                {
                    return(designTypeResult);
                }
                designType = designTypeResult.DesignType;
            }
            if (!(designType != null) || !createList)
            {
                return(new DesignTypeResult(sourceType, designType));
            }
            return(designTypeGenerator.GetXamlFriendlyListType(designType));
        }
        private Type GetTypeToInstantiate(IInstanceBuilderContext context, DesignInstanceExtension designMarkupExtension, out string warning)
        {
            warning = null;
            if (designMarkupExtension.Type == null)
            {
                return(null);
            }
            if (designMarkupExtension.IsDesignTimeCreatable && !designMarkupExtension.CreateList)
            {
                return(designMarkupExtension.Type);
            }
            if (!designMarkupExtension.IsDesignTimeCreatable && !DesignTypeInstanceBuilder.IsTypeEmittable(designMarkupExtension.Type))
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                string      instanceBuilderDesignTypeCannotBeLateBound = ExceptionStringTable.InstanceBuilderDesignTypeCannotBeLateBound;
                object[]    name = new object[] { designMarkupExtension.Type.Name };
                warning = string.Format(currentCulture, instanceBuilderDesignTypeCannotBeLateBound, name);
                return(null);
            }
            DesignTypeResult typeToInstantiate = DesignTypeInstanceBuilder.GetTypeToInstantiate(context.DocumentContext.TypeResolver.PlatformMetadata, designMarkupExtension.Type, designMarkupExtension.CreateList, designMarkupExtension.IsDesignTimeCreatable);

            if (!typeToInstantiate.IsFailed)
            {
                return(typeToInstantiate.DesignType);
            }
            if (string.IsNullOrEmpty(typeToInstantiate.Context))
            {
                warning = typeToInstantiate.TypeGenerationException.Message;
            }
            else
            {
                CultureInfo currentUICulture = CultureInfo.CurrentUICulture;
                object[]    message          = new object[] { typeToInstantiate.TypeGenerationException.Message, typeToInstantiate.Context };
                warning = string.Format(currentUICulture, "{0} ({1})", message);
            }
            return(null);
        }