Пример #1
0
        private string GetInlineXmlData(DocumentNode dataSource)
        {
            DocumentCompositeNode documentCompositeNode1 = dataSource as DocumentCompositeNode;

            if (documentCompositeNode1 == null)
            {
                return((string)null);
            }
            DocumentCompositeNode documentCompositeNode2 = documentCompositeNode1.Properties[XmlDataProviderSceneNode.XmlSerializerProperty] as DocumentCompositeNode;

            if (documentCompositeNode2 == null)
            {
                return((string)null);
            }
            DocumentNode node = documentCompositeNode2.Properties[DesignTimeProperties.InlineXmlProperty];

            if (node == null)
            {
                return((string)null);
            }
            using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(node.Context, (IViewRootResolver)null, (ITextBufferService)null))
            {
                using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                {
                    instanceBuilderContext.ViewNodeManager.RootNodePath = new DocumentNodePath(node.DocumentRoot.RootNode, node);
                    instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                }
                return(instanceBuilderContext.ViewNodeManager.Root.Instance as string);
            }
        }
Пример #2
0
        private object ConvertInternal(object value, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext, PlatformConverter.ConvertToType convertType)
        {
            if (value == null)
            {
                return((object)null);
            }
            if (value == PlatformConverter.PortableUserInterfaceFont)
            {
                value = (object)new FontFamily(PlatformConverter.portableUserInterfaceString);
            }
            if (PlatformConverter.IsPlatformValue(value, targetPlatformDocumentContext))
            {
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)targetPlatformDocumentContext.CreateNode(value.GetType(), value));
                }
                return(value);
            }
            Type type1 = value.GetType();

            if (convertType == PlatformConverter.ConvertToType.InstanceValue && PlatformConverter.CanUseFastConversion(type1))
            {
                return(this.ConvertInternalFast(value, sourcePlatformDocumentContext.TypeResolver, targetPlatformDocumentContext.TypeResolver));
            }
            SceneDocument activeDocument = this.designerContext.ActiveDocument;

            ((PurePlatformProjectContext)this.StandaloneWpfDocumentContext.TypeResolver).SetActualProjectContext(activeDocument != null ? activeDocument.ProjectContext : (IProjectContext)null);
            DocumentNode documentNode1 = value as DocumentNode;
            DocumentNode node;

            using (((IProjectContext)sourcePlatformDocumentContext.TypeResolver).Platform.DocumentNodeBuilderFactory.ForceBuildAnimatedValue)
                node = documentNode1 ?? sourcePlatformDocumentContext.CreateNode(value.GetType(), value);
            if (node == null)
            {
                return((object)null);
            }
            object obj          = (object)null;
            IType  type2        = node.Type;
            IType  platformType = ((IPlatformTypes)targetPlatformDocumentContext.TypeResolver.PlatformMetadata).GetPlatformType(type2.FullName);

            if (node is DocumentPrimitiveNode)
            {
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext));
                }
                if (platformType == null || type2.TypeConverter == null || platformType.TypeConverter == null)
                {
                    return((object)null);
                }
                DocumentPrimitiveNode documentPrimitiveNode1 = value as DocumentPrimitiveNode;
                string text;
                if (documentPrimitiveNode1 != null)
                {
                    text = documentPrimitiveNode1.GetValue <string>();
                }
                else
                {
                    DocumentPrimitiveNode documentPrimitiveNode2 = node as DocumentPrimitiveNode;
                    text = documentPrimitiveNode2 == null || !(documentPrimitiveNode2.Value is DocumentNodeStringValue) ? type2.TypeConverter.ConvertToString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, value) : documentPrimitiveNode2.GetValue <string>();
                }
                try
                {
                    obj = platformType.TypeConverter.ConvertFromString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, text);
                }
                catch
                {
                }
            }
            else
            {
                DocumentNode documentNode2 = this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext);
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)documentNode2);
                }
                if (documentNode2 != null)
                {
                    DocumentNodePath documentNodePath = new DocumentNodePath(documentNode2, documentNode2);
                    using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(targetPlatformDocumentContext, this.designerContext))
                    {
                        instanceBuilderContext.ViewNodeManager.RootNodePath = documentNodePath;
                        instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                        using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                            obj = instanceBuilderContext.ViewNodeManager.ValidRootInstance;
                        instanceBuilderContext.ViewNodeManager.RootNodePath = (DocumentNodePath)null;
                    }
                }
            }
            if (obj == null && platformType != null && (!platformType.SupportsNullValues && platformType.RuntimeType != (Type)null))
            {
                obj = InstanceBuilderOperations.InstantiateType(platformType.RuntimeType, true);
            }
            return(obj);
        }