Created
May 9, 2013 00:59
-
-
Save pawelpabich/5544814 to your computer and use it in GitHub Desktop.
Deep clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Runtime.Serialization; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
public class Structure | |
{ | |
public Structure() | |
{ | |
DateTime = DateTime.Now; | |
Int = 12; | |
SubStructure = new SubStructure(); | |
List = new[] {new SubStructure(), new SubStructure(), new SubStructure(), }; | |
} | |
public int Int { get; set; } | |
public DateTime DateTime | |
{ | |
get; | |
set; | |
} | |
public SubStructure SubStructure { get; set; } | |
public IEnumerable<SubStructure> List { get; set; } | |
} | |
public class SubStructure | |
{ | |
public SubStructure() | |
{ | |
String = Guid.NewGuid().ToString(); | |
} | |
public String String { get; set; } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var input = new Structure(); | |
var serializer = new NetDataContractSerializer(); | |
var stream = new MemoryStream(); | |
serializer.Serialize(stream, input); | |
stream.Seek(0, SeekOrigin.Begin); | |
var copy = (Structure)serializer.Deserialize(stream); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment