tips & tricks


Calendario
febbraio 2025
lmmgvsd
272829303112
3456789
10111213141516
17181920212223
242526272812
3456789

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: 15.301
  • Views Posts: 58.680
  • 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