Exemple #1
0
        private DocumentNode ConvertSubtree(DocumentNode node, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext)
        {
            DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentPrimitiveNode != null)
            {
                ITypeId typeId        = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentPrimitiveNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                object  valueAsObject = DocumentPrimitiveNode.GetValueAsObject((DocumentNode)documentPrimitiveNode);
                if (valueAsObject != null)
                {
                    return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, this.ConvertInternal(valueAsObject, sourcePlatformDocumentContext, targetPlatformDocumentContext, PlatformConverter.ConvertToType.InstanceValue)));
                }
                IDocumentNodeValue documentNodeValue = DocumentPrimitiveNode.GetValueAsMember((DocumentNode)documentPrimitiveNode) != null || documentPrimitiveNode.Value == null ? (IDocumentNodeValue)null : documentPrimitiveNode.Value.Clone(targetPlatformDocumentContext);
                return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, documentNodeValue));
            }
            if (documentCompositeNode != null)
            {
                if (PlatformTypes.CompositeTransform.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                {
                    IPlatform platform = PlatformConverter.GetPlatform(sourcePlatformDocumentContext);
                    if (platform != null)
                    {
                        TransformGroup transformGroup = platform.GeometryHelper.ConvertTransformToWpf((object)documentCompositeNode);
                        if (PlatformConverter.IsPlatformValue((object)transformGroup, targetPlatformDocumentContext))
                        {
                            return(targetPlatformDocumentContext.CreateNode(typeof(TransformGroup), (object)transformGroup));
                        }
                    }
                }
                ITypeId typeId = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentCompositeNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                if (!documentCompositeNode.TypeResolver.PlatformMetadata.IsNullType(typeId))
                {
                    DocumentCompositeNode node1 = targetPlatformDocumentContext.CreateNode(typeId);
                    foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode.Properties)
                    {
                        IProperty property = this.ConvertPropertyKey(keyValuePair.Key, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                        if (property != null)
                        {
                            DocumentNode node2 = keyValuePair.Value;
                            if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)node2.Type) && !PlatformTypes.Style.IsAssignableFrom((ITypeId)node2.Type))
                            {
                                DocumentNode node3 = this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext);
                                if (node3 != null && (PlatformTypeHelper.GetPropertyType(property).IsAssignableFrom(node3.TargetType) || DocumentNodeUtilities.IsMarkupExtension(node3)))
                                {
                                    node1.Properties[(IPropertyId)property] = node3;
                                }
                            }
                        }
                    }
                    if (documentCompositeNode.SupportsChildren)
                    {
                        for (int index = 0; index < documentCompositeNode.Children.Count; ++index)
                        {
                            DocumentNode node2 = documentCompositeNode.Children[index];
                            node1.Children.Add(this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext));
                        }
                    }
                    return((DocumentNode)node1);
                }
            }
            return((DocumentNode)null);
        }