Ejemplo n.º 1
0
        private static bool GetPolySegmentAsString(DocumentCompositeNode polySegmentNode, StringBuilder stringBuilder, char symbol, IPropertyId pointsProperty)
        {
            DocumentPrimitiveNode item = polySegmentNode.Properties[pointsProperty] as DocumentPrimitiveNode;

            if (item == null)
            {
                return(false);
            }
            PointCollection value = item.GetValue <PointCollection>();

            stringBuilder.Append(' ');
            stringBuilder.Append(symbol);
            stringBuilder.Append(PointSerializationHelper.GetPointCollectionAsString(value));
            return(true);
        }
Ejemplo n.º 2
0
        public virtual string GetValueAsString(DocumentNode node)
        {
            ITypeId type       = node.Type;
            Type    targetType = node.TargetType;
            DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentPrimitiveNode != null)
            {
                DocumentNodeStringValue value          = documentPrimitiveNode.Value as DocumentNodeStringValue;
                TypeConverter           valueConverter = documentPrimitiveNode.ValueConverter;
                if (value != null && valueConverter != null && valueConverter.CanConvertFrom(typeof(string)))
                {
                    if (typeof(Vector3DCollection) == targetType)
                    {
                        Vector3DCollection vector3DCollections = (Vector3DCollection)valueConverter.ConvertFromInvariantString(value.Value);
                        return(PointSerializationHelper.GetVector3DCollectionAsString(vector3DCollections));
                    }
                    if (typeof(Point3DCollection) == targetType)
                    {
                        Point3DCollection point3DCollections = (Point3DCollection)valueConverter.ConvertFromInvariantString(value.Value);
                        return(PointSerializationHelper.GetPoint3DCollectionAsString(point3DCollections));
                    }
                    if (typeof(PointCollection) == targetType)
                    {
                        PointCollection pointCollections = (PointCollection)valueConverter.ConvertFromInvariantString(value.Value);
                        return(PointSerializationHelper.GetPointCollectionAsString(pointCollections));
                    }
                }
            }
            else if (documentCompositeNode != null)
            {
                if (PlatformTypes.PathGeometry.IsAssignableFrom(type))
                {
                    return(PathGeometrySerializationHelper.SerializeAsAttribute(documentCompositeNode));
                }
                if (PlatformTypes.PathFigureCollection.IsAssignableFrom(type))
                {
                    return(PathGeometrySerializationHelper.SerializeAsAttribute(documentCompositeNode));
                }
                if (PlatformTypes.DoubleCollection.IsAssignableFrom(type))
                {
                    return(PointSerializationHelper.SerializeDoubleCollectionAsAttribute(documentCompositeNode));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static string GetPointCollectionAsString(PointCollection collection)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < collection.Count; i++)
            {
                PointSerializationHelper.AppendPoint(stringBuilder, collection[i]);
                if (i % 23 == 22)
                {
                    stringBuilder.AppendLine();
                }
                else if (i < collection.Count - 1)
                {
                    stringBuilder.Append(' ');
                }
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 4
0
 private static bool GetSimpleSegmentAsString(DocumentCompositeNode simpleSegmentNode, StringBuilder stringBuilder, char symbol, params IPropertyId[] pointProperties)
 {
     stringBuilder.Append(' ');
     stringBuilder.Append(symbol);
     for (int i = 0; i < (int)pointProperties.Length; i++)
     {
         Point point = new Point();
         if (PathGeometrySerializationHelper.GetPrimitiveValue <Point>(simpleSegmentNode, pointProperties[i], ref point) == PathGeometrySerializationHelper.PropertyValueKind.Composite)
         {
             return(false);
         }
         if (i > 0)
         {
             stringBuilder.Append(' ');
         }
         PointSerializationHelper.AppendPoint(stringBuilder, point);
     }
     return(true);
 }
Ejemplo n.º 5
0
        private static bool GetArcSegmentAsString(DocumentCompositeNode arcSegmentNode, StringBuilder stringBuilder)
        {
            Size           size           = new Size();
            double         num            = 0;
            bool           flag           = false;
            SweepDirection sweepDirection = SweepDirection.Counterclockwise;
            Point          point          = new Point();

            if (PathGeometrySerializationHelper.GetPrimitiveValue <Size>(arcSegmentNode, PathMetadata.ArcSegmentSizeProperty, ref size) == PathGeometrySerializationHelper.PropertyValueKind.Composite || PathGeometrySerializationHelper.GetPrimitiveValue <double>(arcSegmentNode, PathMetadata.ArcSegmentRotationAngleProperty, ref num) == PathGeometrySerializationHelper.PropertyValueKind.Composite || PathGeometrySerializationHelper.GetPrimitiveValue <bool>(arcSegmentNode, PathMetadata.ArcSegmentIsLargeArcProperty, ref flag) == PathGeometrySerializationHelper.PropertyValueKind.Composite || PathGeometrySerializationHelper.GetPrimitiveValue <SweepDirection>(arcSegmentNode, PathMetadata.ArcSegmentSweepDirectionProperty, ref sweepDirection) == PathGeometrySerializationHelper.PropertyValueKind.Composite || PathGeometrySerializationHelper.GetPrimitiveValue <Point>(arcSegmentNode, PathMetadata.ArcSegmentPointProperty, ref point) == PathGeometrySerializationHelper.PropertyValueKind.Composite)
            {
                return(false);
            }
            StringBuilder stringBuilder1 = stringBuilder;

            object[] width = new object[] { size.Width, size.Height, num, null, null };
            width[3] = (flag ? '1' : '0');
            width[4] = (sweepDirection == SweepDirection.Clockwise ? '1' : '0');
            stringBuilder1.AppendFormat(" A{0:G8},{1:G8},{2:G8},{3},{4},", width);
            PointSerializationHelper.AppendPoint(stringBuilder, point);
            return(true);
        }
Ejemplo n.º 6
0
        private SerializedFormat ShouldSerializeProperty(XamlSerializerContext serializerContext, DocumentCompositeNode parentNode, IPropertyId propertyKey, DocumentNode valueNode, out bool useElementForOuterMostMarkupExtension)
        {
            bool             flag;
            SerializedFormat serializedFormat;

            useElementForOuterMostMarkupExtension = false;
            DocumentCompositeNode documentCompositeNode = valueNode as DocumentCompositeNode;
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;
            IProperty             valueProperty         = valueNode.GetValueProperty();

            if (valueProperty != null)
            {
                if (valueProperty.MemberType != MemberType.DesignTimeProperty && !this.ShouldSerialize(serializerContext, valueNode))
                {
                    return(SerializedFormat.DoNotSerialize);
                }
                if (valueProperty.MemberType == MemberType.DesignTimeProperty)
                {
                    bool flag1 = true;
                    if (!valueProperty.ShouldSerialize)
                    {
                        flag1 = this.ShouldSerializeDesignTimeProperty(valueProperty);
                    }
                    if (!flag1)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                if (!KnownProperties.SetterTargetNameProperty.Equals(valueProperty))
                {
                    if (parentNode.Type.Metadata.IsNameProperty(valueProperty))
                    {
                        string valueAsString = DocumentPrimitiveNode.GetValueAsString(valueNode);
                        if (valueAsString != null)
                        {
                            if (valueAsString.StartsWith("~", StringComparison.Ordinal) && serializerContext.InStyleOrTemplate)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                            if (valueAsString.Length == 0)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    if (DesignTimeProperties.UidProperty.Equals(valueProperty))
                    {
                        return(SerializedFormat.ComplexString);
                    }
                    if (KnownProperties.FrameworkContentElementResourcesProperty.Equals(valueProperty))
                    {
                        if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(documentCompositeNode.Type) && documentCompositeNode.SupportsChildren && documentCompositeNode.Children.Count == 0)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (!PlatformTypes.Style.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        DependencyPropertyReferenceStep dependencyPropertyReferenceStep = valueProperty as DependencyPropertyReferenceStep;
                        if (dependencyPropertyReferenceStep != null && dependencyPropertyReferenceStep.IsAttachable && !DefaultXamlSerializerFilter.IsTypeSerializable(serializerContext.TypeResolver, valueProperty.DeclaringType) && dependencyPropertyReferenceStep.MemberType != MemberType.DesignTimeProperty)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentCompositeNode != null)
                    {
                        if (documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsDefaultStyleProperty))
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentPrimitiveNode != null && documentPrimitiveNode.Value is DocumentNodeReferenceValue)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                else
                {
                    string str = DocumentPrimitiveNode.GetValueAsString(valueNode);
                    if (str != null && str == "~Self")
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
            }
            IType type = valueNode.Type;

            if (PlatformTypes.XData.Equals(type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.StaticResource.IsAssignableFrom(type) && documentCompositeNode != null && ResourceNodeHelper.GetResourceKey(documentCompositeNode) != null)
            {
                DocumentCompositeNode parent = documentCompositeNode.Parent;
                while (parent != null && parent.Type.IsExpression)
                {
                    parent = parent.Parent;
                }
                if (parent != null)
                {
                    IPropertyId resourcesProperty = parent.Type.Metadata.ResourcesProperty;
                    if (resourcesProperty != null)
                    {
                        DocumentCompositeNode item = parent.Properties[resourcesProperty] as DocumentCompositeNode;
                        if (item != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(item.Type))
                        {
                            useElementForOuterMostMarkupExtension = true;
                            return(SerializedFormat.ComplexString);
                        }
                    }
                }
            }
            if (type.IsExpression)
            {
                if (documentCompositeNode != null)
                {
                    using (IEnumerator <KeyValuePair <IProperty, DocumentNode> > enumerator = documentCompositeNode.Properties.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            KeyValuePair <IProperty, DocumentNode> current = enumerator.Current;
                            switch (this.ShouldSerializeProperty(serializerContext, documentCompositeNode, current.Key, current.Value, out flag))
                            {
                            case SerializedFormat.SimpleString:
                            {
                                continue;
                            }

                            case SerializedFormat.ComplexString:
                            {
                                if (current.Value.Type.IsExpression)
                                {
                                    if (!flag)
                                    {
                                        continue;
                                    }
                                    useElementForOuterMostMarkupExtension = true;
                                    continue;
                                }
                                else
                                {
                                    serializedFormat = SerializedFormat.Element;
                                    return(serializedFormat);
                                }
                            }
                            }
                            serializedFormat = SerializedFormat.Element;
                            return(serializedFormat);
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    return(serializedFormat);
                }
                return(SerializedFormat.ComplexString);
            }
            if (this.PropertyValueRequiresElement(valueProperty, valueNode.Type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.Uri.IsAssignableFrom(type))
            {
                return(SerializedFormat.ComplexString);
            }
            if (PlatformTypes.PropertyPath.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (DocumentPrimitiveNode.GetValueAsString(documentCompositeNode.Properties[KnownProperties.PropertyPathPathProperty]) != null)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (PlatformTypes.SolidColorBrush.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (documentCompositeNode.Properties.Count == 0)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    if (documentCompositeNode.Properties.Count == 1)
                    {
                        DocumentPrimitiveNode item1 = documentCompositeNode.Properties[KnownProperties.SolidColorBrushColorProperty] as DocumentPrimitiveNode;
                        if (item1 != null && PlatformTypes.Color.Equals(item1.Type))
                        {
                            return(SerializedFormat.SimpleString);
                        }
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (!PlatformTypes.Color.IsAssignableFrom(type))
            {
                if (PlatformTypes.PathGeometry.IsAssignableFrom(type))
                {
                    if (valueProperty == null || PlatformTypes.PathGeometry.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        return(SerializedFormat.Element);
                    }
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.PathFigureCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.DoubleCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && PointSerializationHelper.SerializeDoubleCollectionAsAttribute(documentCompositeNode) == null)
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
            }
            else if (documentCompositeNode == null && valueNode.Parent != null && valueNode.IsProperty)
            {
                return(SerializedFormat.SimpleString);
            }
            if (documentPrimitiveNode != null && documentPrimitiveNode.Value == null)
            {
                return(SerializedFormat.SimpleString);
            }
            if (XamlSerializerContext.IsXmlElement(valueNode))
            {
                return(SerializedFormat.Element);
            }
            if (documentPrimitiveNode != null)
            {
                if (documentPrimitiveNode.Value is DocumentNodeStringValue)
                {
                    return(SerializedFormat.SimpleString);
                }
                if (documentPrimitiveNode.Value is DocumentNodeMemberValue)
                {
                    return(SerializedFormat.SimpleString);
                }
            }
            if (documentCompositeNode == null)
            {
                return(SerializedFormat.ComplexString);
            }
            return(SerializedFormat.Element);
        }
Ejemplo n.º 7
0
        private static bool GetPathFigureAsString(DocumentNode pathFigureNode, StringBuilder stringBuilder)
        {
            bool                  flag;
            bool                  flag1;
            StringBuilder         stringBuilder1;
            DocumentCompositeNode documentCompositeNode = pathFigureNode as DocumentCompositeNode;

            if (documentCompositeNode == null)
            {
                return(false);
            }
            if (PathGeometrySerializationHelper.IsCompositeOrNonDefaultValue <bool>(documentCompositeNode, PathMetadata.PathFigureIsFilledProperty, true))
            {
                return(false);
            }
            Point point = new Point();

            if (PathGeometrySerializationHelper.GetPrimitiveValue <Point>(documentCompositeNode, PathMetadata.PathFigureStartPointProperty, ref point) == PathGeometrySerializationHelper.PropertyValueKind.Composite)
            {
                return(false);
            }
            stringBuilder.Append('M');
            PointSerializationHelper.AppendPoint(stringBuilder, point);
            DocumentNode item = documentCompositeNode.Properties[PathMetadata.PathFigureSegmentsProperty];

            if (item != null)
            {
                DocumentCompositeNode documentCompositeNode1 = item as DocumentCompositeNode;
                if (documentCompositeNode1 == null)
                {
                    return(false);
                }
                using (IEnumerator <DocumentNode> enumerator = documentCompositeNode1.Children.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        if (PathGeometrySerializationHelper.GetPathSegmentAsString(enumerator.Current, stringBuilder))
                        {
                            continue;
                        }
                        flag1 = false;
                        return(flag1);
                    }
                    flag = false;
                    if (PathGeometrySerializationHelper.GetPrimitiveValue <bool>(documentCompositeNode, PathMetadata.PathFigureIsClosedProperty, ref flag) == PathGeometrySerializationHelper.PropertyValueKind.Composite)
                    {
                        return(false);
                    }
                    if (flag)
                    {
                        stringBuilder1 = stringBuilder.Append(" z");
                    }
                    return(true);
                }
                return(flag1);
            }
            flag = false;
            if (PathGeometrySerializationHelper.GetPrimitiveValue <bool>(documentCompositeNode, PathMetadata.PathFigureIsClosedProperty, ref flag) == PathGeometrySerializationHelper.PropertyValueKind.Composite)
            {
                return(false);
            }
            if (flag)
            {
                stringBuilder1 = stringBuilder.Append(" z");
            }
            return(true);
        }