/// <summary> /// 序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <returns></returns> public static string Serialize <T>(T value) { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); XmlSerializer serializer = new XmlSerializer(typeof(T)); using (StringUTF8Writer writer = new StringUTF8Writer(new StringBuilder())) { serializer.Serialize(writer, value, namespaces); return(writer.ToString()); } }
public static string SerializeList <T>(IList <T> entryList) { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); XmlSerializer serializer = new XmlSerializer(typeof(List <T>)); using (StringUTF8Writer writer = new StringUTF8Writer(new StringBuilder())) { serializer.Serialize(writer, entryList, namespaces); return(writer.ToString()); } }