You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
namespace GeoSigma.SigmaDrawerStyle
{
[XmlRoot("HowToViewCurve")]
public class DrawerCurveStyle
{
//[XmlElement(ElementName = "Base")]
//public CurveStyleBase Base
//{
// get;set;
//}
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("Source")]
public int Source { get; set; }
// [XmlArrayAttribute("Areas")]
// [XmlArrayItem("Property")]
// [XmlElement(ElementName = "Property")]
[XmlElement("Base", typeof(CurveStyleBase))]
[XmlElement("Mark2", typeof(CurveTwoMark))]
[XmlElement("Property", typeof(CurveProperty))]
[XmlElement("ArrowHead", typeof(CurveArrowHead))]
[XmlElement("ArrowTail", typeof(CurveArrowTail))]
[XmlElement("Location", typeof(CurveLocation))]
[XmlElement("ScaleSymbol", typeof(CurveScaleSymbol))]
[XmlElement("CurveName", typeof(CurveName))]
[XmlElement("FillSymbol", typeof(CurveFillSymbol))]
[XmlElement("InName", typeof(CurveInName))]
[XmlElement("InNameAny", typeof(CurveInNameAny))]
[XmlElement("CenterName", typeof(CurveCenterName))]
[XmlElement("Effect", typeof(CurveEffect))]
public List<CurveView> Properties { get; set; } = new List<CurveView>();
public string SerialXml()
{
string strData = "";
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineChars = "\r\n";
settings.Encoding = Encoding.Default;
//去除xml声明
settings.OmitXmlDeclaration = true;
System.IO.MemoryStream mem = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(mem, settings))
{
// 去除默认命名空间xmlns:xsd和xmlns:xsi
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
XmlSerializer formatter = new XmlSerializer(this.GetType());
formatter.Serialize(writer, this, ns);
}
return Encoding.Default.GetString(mem.ToArray());
}
/// <summary>
/// Deserials the XML.
/// </summary>
/// <param name="xml">The XML.</param>
/// <returns></returns>
public virtual DrawerCurveStyle DeserialXml(string xml)
{
var xs = new XmlSerializer(this.GetType());
using (MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(xml)))
{
var obj = xs.Deserialize(stream) as DrawerCurveStyle;
return obj;
}
}
}
public class CurveStyleBase : CurveView
{
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("Style")]
public int Style { get; set; }
}
}