tips & tricks


Calendario
aprile 2025
lmmgvsd
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

Serialize Object to string

Serialize Object to string



public static string Serialize(object o, Type T) { //this avoids xml document declaration XmlWriterSettings settings = new XmlWriterSettings() { Indent = false, OmitXmlDeclaration = true }; var stream = new MemoryStream(); using (XmlWriter xw = XmlWriter.Create(stream, settings)) { //this avoids xml namespace declaration XmlSerializerNamespaces ns = new XmlSerializerNamespaces( new[] { XmlQualifiedName.Empty }); XmlSerializer x = new XmlSerializer(T, ""); x.Serialize(xw, o, ns); } return Encoding.UTF8.GetString(stream.ToArray()); }
Categoria: C#
martedì, 23 gen 2018 Ore. 12.07
Archivio Posts
Anno 2020

Anno 2018

Anno 2015

Anno 2013

Anno 2011

Anno 2010

Anno 2009

Anno 2008
Statistiche
  • Views Home Page: 16.490
  • Views Posts: 60.349
  • Views Gallerie: 2.837
  • n° Posts: 117
  • n° Commenti: 1
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003