-
-
Save chrisnicola/1254492 to your computer and use it in GitHub Desktop.
This file contains 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; | |
namespace JSONTestingAgain | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var test = new TestClass { TestGuid = Guid.NewGuid(), TestString = "blah" }; | |
test.TestDictionary.Add(Guid.NewGuid(), "testStringValue"); | |
test.TestDictionary.Add(Guid.NewGuid(), Guid.NewGuid()); | |
var nancyResult = Nancy(test); | |
var microsoftResult = Microsoft(test); | |
Console.WriteLine(nancyResult); | |
Console.WriteLine(microsoftResult); | |
Console.ReadLine(); | |
} | |
private static TestClass Microsoft(TestClass test) | |
{ | |
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); | |
var result = serializer.Serialize(test); | |
var newOne = serializer.Deserialize<TestClass>(result); | |
return newOne; | |
} | |
private static TestClass Nancy(TestClass test) | |
{ | |
var serializer = new Nancy.Json.JavaScriptSerializer(); | |
var result = serializer.Serialize(test); | |
var newOne = serializer.Deserialize<TestClass>(result); | |
return newOne; | |
} | |
} | |
public class TestClass | |
{ | |
public Guid TestGuid { get; set; } | |
public String TestString { get; set; } | |
public Dictionary<Guid, object> TestDictionary { get; set; } | |
public TestClass() | |
{ | |
this.TestDictionary = new Dictionary<Guid, object>(); | |
} | |
public override string ToString() | |
{ | |
return String.Format( | |
"{0} {1} {2}", | |
TestGuid, | |
TestString, | |
this.TestDictionary.Select(kv => kv.Key.ToString() + ":" + kv.Value.ToString()).Aggregate( | |
(kv1, kv2) => kv1 + "," + kv2)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment