Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Runtime.Serialization;
- namespace TestApp
- {
- public interface ICloneable<out T>
- {
- T Clone();
- }
- [DataContract(Name = "Test2_name", Namespace = "Test2_namespace")]
- public class Test2 : ICloneable<Test2>
- {
- private string _message = string.Empty;
- [DataMember(Name = "Message")]
- public string Message
- {
- get { return _message; }
- set { _message = value; }
- }
- public Test2 Clone()
- {
- var serializer = new DataContractSerializer(typeof(Test2), null, int.MaxValue, false, true, null);
- using (var ms = new MemoryStream())
- {
- serializer.WriteObject(ms, this);
- ms.Position = 0;
- return (Test2)serializer.ReadObject(ms);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Test2 test2 = new Test2();
- test2.Message = "hello";
- var s2 = test2.Clone();
- Console.WriteLine(s2.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement