Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created April 26, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theburningmonk/3b1f1a33ba616bda7474 to your computer and use it in GitHub Desktop.
Save theburningmonk/3b1f1a33ba616bda7474 to your computer and use it in GitHub Desktop.
Testing DataContractSerializer in .Net 4.5.1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.IO;
using System.Xml;
namespace DCSerializerTest
{
[DataContract]
public class KeywordFunctionMap
{
[DataMember]
public Dictionary<string, string> Map { get; set; }
public KeywordFunctionMap()
{
Map = new Dictionary<string, string>();
}
}
class Program
{
static void Main(string[] args)
{
var serializer = new DataContractSerializer(typeof(KeywordFunctionMap));
string xmlString;
var obj = new KeywordFunctionMap();
obj.Map.Add("1", "one");
using (var sw = new StringWriter())
{
using (var writer = new XmlTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
serializer.WriteObject(writer, obj);
writer.Flush();
xmlString = sw.ToString();
}
}
Console.WriteLine(xmlString);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment