Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace ConsoleApplication1
- {
- [DataContract]
- [KnownType(typeof(B))]
- public class A
- {
- [DataMember]
- public Dictionary<string, object> Dict { get; set; }
- }
- [DataContract]
- public class B
- {
- [DataMember]
- public string X { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var obj = new A
- {
- Dict = new Dictionary<string, object>
- {
- { "a", new B { X = "123" } }
- }
- };
- new DataContractSerializer(typeof(A)).WriteObject(Stream.Null, obj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement