Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11. [DataContract]
  12. [KnownType(typeof(B))]
  13. public class A
  14. {
  15. [DataMember]
  16. public Dictionary<string, object> Dict { get; set; }
  17. }
  18.  
  19. [DataContract]
  20. public class B
  21. {
  22. [DataMember]
  23. public string X { get; set; }
  24. }
  25.  
  26. class Program
  27. {
  28. static void Main(string[] args)
  29. {
  30. var obj = new A
  31. {
  32. Dict = new Dictionary<string, object>
  33. {
  34. { "a", new B { X = "123" } }
  35. }
  36. };
  37.  
  38. new DataContractSerializer(typeof(A)).WriteObject(Stream.Null, obj);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement