Skip to content

Latest commit

 

History

History
41 lines (34 loc) · 875 Bytes

Clone.md

File metadata and controls

41 lines (34 loc) · 875 Bytes

Cloning JSON with JToken.DeepClone

This sample recursively clones a Argon.JToken and all its children using Argon.JToken.DeepClone.

var o1 = new JObject
{
    {"String", "A string!"},
    {"Items", new JArray(1, 2)}
};

Console.WriteLine(o1.ToString());
// {
//   "String": "A string!",
//   "Items": [
//     1,
//     2
//   ]
// }

var o2 = (JObject) o1.DeepClone();

Console.WriteLine(o2.ToString());
// {
//   "String": "A string!",
//   "Items": [
//     1,
//     2
//   ]
// }

Console.WriteLine(JToken.DeepEquals(o1, o2));
// true

Console.WriteLine(ReferenceEquals(o1, o2));
// false

snippet source | anchor