public MyXmlSerializer(Type clrType) { type = clrType; XmlAttributeOverrides overrides = ObjectEx.GetXmlOverrides(clrType); XmlSerializer = new XmlSerializer(clrType, overrides); Locker = new object(); IsLock = false; }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <returns></returns> public static string ToMsgXml <T>(this T item) where T : class { if (item == null) { return(null); } Type t = item.GetType(); XmlAttributeOverrides overrides = ObjectEx.GetXmlOverrides(t); XmlSerializer serializer = new XmlSerializer(t, overrides); StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sb, XmlEx.WriterSettings)) { serializer.Serialize(writer, item); } return(sb.ToString()); }