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
2.9 KiB
C#

using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace GeoSigma.SigmaDrawerStyle
{
public class DrawerStyle
{
public DrawerCurveStyle CurveStyle { set; get; }
public DrawerPointStyle PontStyle { set; get; }
//public DrawerElementProperty ElementProperty { set; get; }
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 = false;
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 DrawerStyle DeserialXml(string xml)
{
var xs = new XmlSerializer(this.GetType());
using (MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(xml)))
{
var obj = xs.Deserialize(stream) as DrawerStyle;
return obj;
}
}
public void DeserializeCurve(string data)
{
using (StringReader reader = new StringReader(data))
{
try
{
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(DrawerCurveStyle));
CurveStyle = xmlSerializer.Deserialize(reader) as DrawerCurveStyle;
}
catch (Exception ex)
{
string ss = ex.Message;
CurveStyle = null;
}
}
}
public void DeserializePoint(string data)
{
using (StringReader reader = new StringReader(data))
{
try
{
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(DrawerPointStyle));
PontStyle = xmlSerializer.Deserialize(reader) as DrawerPointStyle;
}
catch (Exception ex)
{
PontStyle = null;
}
}
}
}
}