Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class Program
  2. {
  3. class A { }
  4. class B { }
  5.  
  6. public static void Main()
  7. {
  8. Dictionary<string, object> dict = new Dictionary<string, object>();
  9. dict["Foo"] = new A();
  10. dict["Bar"] = new B();
  11. dict["Baz"] = new object();
  12. dict["Rainbow"] = Color.FromArgb(20, 20, 20, 20);
  13.  
  14. var ser = new JsonSerializer
  15. {
  16. TypeNameHandling = TypeNameHandling.Auto
  17. };
  18. var w = new JsonTextWriter(Console.Out)
  19. {
  20. Formatting = Formatting.Indented
  21. };
  22. ser.Serialize(w, dict);
  23. }
  24. }
  25.  
  26. {
  27. "Foo": {
  28. "$type": "Program+A, mi1i2eqo"
  29. },
  30. "Bar": {
  31. "$type": "Program+B, mi1i2eqo"
  32. },
  33. "Baz": {},
  34. "Rainbow": "20, 20, 20, 20"
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement