Answer by Marek Mucha for Serialize an object to string
Universal xml, json and bin serializer/deserializer from and to stringpublic static class SerializationHelper{ public static string Serialize<T>(this T toSerialize, OutTypeEnum oType) { if(oType...
View ArticleAnswer by Petteri Kautonen for Serialize an object to string
I felt a like I needed to share this manipulated code to the accepted answer - as I have no reputation, I'm unable to comment..using System;using System.Xml.Serialization;using System.IO;namespace...
View ArticleAnswer by Brian for Serialize an object to string
[VB]Public Function XmlSerializeObject(ByVal obj As Object) As String Dim xmlStr As String = String.Empty Dim settings As New XmlWriterSettings() settings.Indent = False settings.OmitXmlDeclaration =...
View ArticleAnswer by TPG for Serialize an object to string
public static string SerializeObject<T>(T objectToSerialize) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new...
View ArticleAnswer by satibel for Serialize an object to string
In some rare cases you might want to implement your own String serialization. But that probably is a bad idea unless you know what you are doing. (e.g. serializing for I/O with a batch file)Something...
View ArticleAnswer by Thomas Tiveron for Serialize an object to string
I was unable to use the JSONConvert method suggested by xhafanIn .Net 4.5 even after adding the "System.Web.Extensions" assembly reference I was still unable to access the JSONConvert.However, once you...
View ArticleAnswer by oPless for Serialize an object to string
My 2p... string Serialise<T>(T serialisableObject) { var xmlSerializer = new XmlSerializer(serialisableObject.GetType()); using (var ms = new MemoryStream()) { using (var xw =...
View ArticleAnswer by ADM-IT for Serialize an object to string
Serialize and Deserialize XML/JSON (SerializationHelper.cs) (You can use Newtonsoft.Json Nuget Package for JSON serialization):using Newtonsoft.Json;using System.IO;using...
View ArticleAnswer by xhafan for Serialize an object to string
I know this is not really an answer to the question, but based on the number of votes for the question and the accepted answer, I suspect the people are actually using the code to serialize an object...
View ArticleAnswer by Fulvio for Serialize an object to string
Code Safety NoteRegarding the accepted answer, it is important to use toSerialize.GetType() instead of typeof(T) in XmlSerializer constructor: if you use the first one the code covers all possible...
View ArticleAnswer by dtb for Serialize an object to string
Use a StringWriter instead of a StreamWriter:public static string SerializeObject<T>(this T toSerialize){ XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());...
View ArticleSerialize an object to string
I have the following method to save an Object to a file:// Save an object out to the diskpublic static void SerializeObject<T>(this T toSerialize, String filename){ XmlSerializer xmlSerializer =...
View Article