Created
April 26, 2015 09:14
-
-
Save theburningmonk/3b1f1a33ba616bda7474 to your computer and use it in GitHub Desktop.
Testing DataContractSerializer in .Net 4.5.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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