public static ToXml ( object obj, bool includetype = false ) : System.Xml.Linq.XElement | ||
obj | object | |
includetype | bool | |
Результат | System.Xml.Linq.XElement |
private static string ToXML <T>(T obj, bool includetype, bool indent = false) { if (includetype) { XElement xml = XMLConverter.ToXml(obj, null, includetype); if (indent) { return(xml.ToString()); } else { return(xml.ToString(SaveOptions.DisableFormatting)); } } else { System.Xml.Serialization.XmlSerializerNamespaces ns = new System.Xml.Serialization.XmlSerializerNamespaces(); XmlSerializer xs = new XmlSerializer(typeof(T)); StringBuilder sbuilder = new StringBuilder(); var xmlws = new System.Xml.XmlWriterSettings() { OmitXmlDeclaration = true, Indent = indent }; ns.Add(string.Empty, string.Empty); using (var writer = System.Xml.XmlWriter.Create(sbuilder, xmlws)) { xs.Serialize(writer, obj, ns); } string result = sbuilder.ToString(); ns = null; xs = null; sbuilder = null; xmlws = null; return(result); } }