public static AbstractGeometryType Deserialize(XmlReader reader) { var node = XElement.Load(reader); reader = node.CreateReader(); if (node.Name.NamespaceName != "http://www.opengis.net/gml") { throw new FormatException("The xml is not GML"); } if (node.Name.LocalName == "MultiPolygon") { return((MultiPolygonType)MultiPolygonSerializer.Deserialize(reader)); } if (node.Name.LocalName == "MultiCurve") { return((MultiCurveType)MultiCurveSerializer.Deserialize(reader)); } if (node.Name.LocalName == "MultiLineString") { return((MultiLineStringType)MultiLineStringSerializer.Deserialize(reader)); } if (node.Name.LocalName == "MultiSurface") { return((MultiSurfaceType)MultiSurfaceSerializer.Deserialize(reader)); } if (node.Name.LocalName == "MultiPoint") { return((MultiPointType)MultiPointSerializer.Deserialize(reader)); } if (node.Name.LocalName == "LinearRing") { return((LinearRingType)LinearRingSerializer.Deserialize(reader)); } if (node.Name.LocalName == "Polygon") { return((PolygonType)PolygonSerializer.Deserialize(reader)); } if (node.Name.LocalName == "LineString") { return((LineStringType)LineStringSerializer.Deserialize(reader)); } if (node.Name.LocalName == "Point") { return((PointType)PointSerializer.Deserialize(reader)); } throw new NotImplementedException(); }
public void TypeSerializer_Test() { var typeSerializer = new PointSerializer(); foreach (var item in Values) { var serialized = typeSerializer.Serialize(1, item); //start from offset serialized = new byte[] {1, 2, 3}.Concat(serialized).ToArray(); var deserialized = typeSerializer.Deserialize(1, serialized, 3, serialized.Length - 3, null); Assert.AreEqual(item, deserialized); } }
public void TypeSerializer_Test() { var typeSerializer = new PointSerializer(); foreach (var item in Values) { var serialized = typeSerializer.Serialize(1, item); //start from offset serialized = new byte[] { 1, 2, 3 }.Concat(serialized).ToArray(); var deserialized = typeSerializer.Deserialize(1, serialized, 3, serialized.Length - 3, null); Assert.AreEqual(item, deserialized); } }
/// <summary> /// Writes the property. /// </summary> /// <param name="name">The property name.</param> /// <param name="type">The property type.</param> /// <param name="value">The property value.</param> private void WriteProperty(string name, Type type, object value) { this.writer.WriteStartElement(PropertyElement); this.writer.WriteAttributeString(NameAttribute, name); this.writer.WriteAttributeString(TypeAttribute, type.AssemblyQualifiedName); if (value == null) { this.writer.WriteAttributeString(IsNullAttribute, TrueValue); } else { this.writer.WriteAttributeString(IsNullAttribute, FalseValue); if (value is Font) { FontSerailizer.WriteType(value, this.writer); } else if (value is Point) { PointSerializer.WriteType(value, this.writer); } else if (value is Size) { SizeSerializer.WriteType(value, this.writer); } else if (value is Color) { ColorSerializer.WriteType(value, this.writer); } else if (value is RecentFiles) { RecentFiles.WriteType(value, this.writer); } else { this.writer.WriteAttributeString(SeralizeAsAttribute, SeralizeAs.Default.ToString()); this.writer.WriteValue(value); } } this.writer.WriteEndElement(); // Property }
/// <summary> /// Reads the property value. /// </summary> /// <returns>The property value.</returns> private object ReadPropertyValue() { SeralizeAs serializeAs = (SeralizeAs)Enum.Parse(typeof(SeralizeAs), this.reader.GetAttribute(SeralizeAsAttribute)); if (serializeAs == SeralizeAs.Font) { return(FontSerailizer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Point) { return(PointSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Size) { return(SizeSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Color) { return(ColorSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.RecentFiles) { return(RecentFiles.ReadType(this.reader)); } else { // SeralizeAs.Default Type type = Type.GetType(this.reader.GetAttribute(TypeAttribute)); if (type.IsEnum) { return(Enum.Parse(type, this.reader.ReadString())); } else if (type == typeof(string)) { return(this.reader.ReadString()); } else { return(Convert.ChangeType(this.reader.ReadString(), type, CultureInfo.CurrentCulture)); } } }
public static void Serialize(XmlWriter writer, AbstractGeometryType gmlObject) { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); namespaces.Add("gml", "http://www.opengis.net/gml/3.2"); if (gmlObject is MultiCurveType) { MultiCurveSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is MultiSurfaceType) { MultiSurfaceSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is MultiPointType) { MultiPointSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is LineStringType) { LineStringSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is PolygonType) { PolygonSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is PointType) { PointSerializer.Serialize(writer, gmlObject, namespaces); return; } throw new NotImplementedException(gmlObject.GetType().ToString()); }