Created
August 5, 2017 22:03
-
-
Save ghstahl/94832b9ba312d9054c783f6e195ec1bf to your computer and use it in GitHub Desktop.
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.Dynamic; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
namespace Hello | |
{ | |
public static class ExpandoObjectExtensions | |
{ | |
public static ExpandoObject Clone(this ExpandoObject original) | |
{ | |
var expandoObjectConverter = new ExpandoObjectConverter(); | |
var originalDoc = JsonConvert.SerializeObject(original, expandoObjectConverter); | |
dynamic clone = JsonConvert.DeserializeObject<ExpandoObject>(originalDoc, expandoObjectConverter); | |
return clone; | |
} | |
public static string ToJson(this ExpandoObject original) | |
{ | |
var expandoObjectConverter = new ExpandoObjectConverter(); | |
var originalDoc = JsonConvert.SerializeObject(original, expandoObjectConverter); | |
return originalDoc; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment