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 Properties { get; set; } = new List(); 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()); } /// /// Deserials the XML. /// /// The XML. /// 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; } } }