public void TestMethod1() { var knowTypes = new List <Type> { }; var serializer = new DataContractSerializer(typeof(Page_Test), knowTypes, int.MaxValue, false, false, new SiteContractSurrogate());//, new ContractResolver());// new DataContractSerializer(typeof(Page));// var page = new Page_Test() { Site = new Site_Test() { Name = "Site1" }, Name = "Page1" }; using (var stream = new MemoryStream()) { serializer.WriteObject(stream, page); stream.Position = 0; Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); // The deserialized object object newMyClass = serializer.ReadObject(stream); Console.WriteLine(newMyClass); } }
public void TestMethod1() { var knowTypes = new List<Type> { }; var serializer = new DataContractSerializer(typeof(Page_Test), knowTypes, int.MaxValue, false, false, new SiteContractSurrogate());//, new ContractResolver());// new DataContractSerializer(typeof(Page));// var page = new Page_Test() { Site = new Site_Test() { Name = "Site1" }, Name = "Page1" }; using (var stream = new MemoryStream()) { serializer.WriteObject(stream, page); stream.Position = 0; Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); // The deserialized object object newMyClass = serializer.ReadObject(stream); Console.WriteLine(newMyClass); } }