提交 a70c5f72 编写于 作者: JasonWcx's avatar JasonWcx

implement XML序列化

上级 5a20a9ce
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Text.RegularExpressions;
using Mozi.HttpEmbedded.DataSerialize;
using Mozi.HttpEmbedded.Serialize;
namespace Mozi.HttpEmbedded.Page
{
......
using System.Collections.Generic;
namespace Mozi.HttpEmbedded.DataSerialize
namespace Mozi.HttpEmbedded.Serialize
{
/// <summary>
/// 数据序列化接口
......
using System;
using System.Collections.Generic;
using Mozi.HttpEmbedded.DataSerialize;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Mozi.HttpEmbedded.Serialize
{
......@@ -9,19 +11,50 @@ namespace Mozi.HttpEmbedded.Serialize
/// </summary>
public class XMLSerializer : ISerializer
{
/// <summary>
/// 反序列化
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
public T Decode<T>(string data)
{
throw new NotImplementedException();
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (StringReader reader = new StringReader(data))
{
return (T)serializer.Deserialize(reader);
}
}
/// <summary>
/// 反列表序列化
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
public IEnumerable<T> DecodeList<T>(string data)
{
throw new NotImplementedException();
XmlSerializer serializer = new XmlSerializer(typeof(List<T>));
using (StringReader reader = new StringReader(data))
{
return (List<T>)serializer.Deserialize(reader);
}
}
/// <summary>
/// 序列化
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public string Encode(object data)
{
throw new NotImplementedException();
XmlSerializer serializer = new XmlSerializer(data.GetType());
string content = string.Empty;
//serialize
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, data);
content = writer.ToString();
};
return content;
}
}
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册