C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
JsonSerializerExtensionMethods.cs
Go to the documentation of this file.
1using System.Linq;
3using Newtonsoft.Json;
4
6{
9 {
14 public static JsonSerializerSettings ShallowCopy(this JsonSerializerSettings settings)
15 {
16 return ReflectionUtilities.ShallowCopy(settings);
17 }
18
21 public static JsonSerializerSettings GetJsonSerializerSettings(this JsonSerializer toCopy)
22 {
23 JsonSerializerSettings copied = new JsonSerializerSettings();
24
25 if (toCopy.Converters != null)
26 copied.Converters = toCopy.Converters.ToList();
27 copied.TypeNameHandling = toCopy.TypeNameHandling;
28 copied.MetadataPropertyHandling = toCopy.MetadataPropertyHandling;
29 copied.TypeNameAssemblyFormatHandling = toCopy.TypeNameAssemblyFormatHandling;
30 copied.PreserveReferencesHandling = toCopy.PreserveReferencesHandling;
31 copied.ReferenceLoopHandling = toCopy.ReferenceLoopHandling;
32 copied.MissingMemberHandling = toCopy.MissingMemberHandling;
33 copied.ObjectCreationHandling = toCopy.ObjectCreationHandling;
34 copied.NullValueHandling = toCopy.NullValueHandling;
35 copied.DefaultValueHandling = toCopy.DefaultValueHandling;
36 copied.ConstructorHandling = toCopy.ConstructorHandling;
37 copied.Context = toCopy.Context;
38 copied.CheckAdditionalContent = toCopy.CheckAdditionalContent;
39 copied.ContractResolver = toCopy.ContractResolver;
40 copied.TraceWriter = toCopy.TraceWriter;
41 copied.EqualityComparer = toCopy.EqualityComparer;
42 copied.SerializationBinder = toCopy.SerializationBinder;
43 copied.Formatting = toCopy.Formatting;
44 copied.DateFormatHandling = toCopy.DateFormatHandling;
45 copied.DateTimeZoneHandling = toCopy.DateTimeZoneHandling;
46 copied.DateParseHandling = toCopy.DateParseHandling;
47 copied.DateFormatString = toCopy.DateFormatString;
48 copied.FloatFormatHandling = toCopy.FloatFormatHandling;
49 copied.FloatParseHandling = toCopy.FloatParseHandling;
50 copied.StringEscapeHandling = toCopy.StringEscapeHandling;
51 copied.Culture = toCopy.Culture;
52 if (toCopy.MaxDepth.HasValue)
53 copied.MaxDepth = toCopy.MaxDepth;
54
55 return copied;
56 }
57 }
58}
Extension Methods to help with copying JsonSerializer settings.
static JsonSerializerSettings ShallowCopy(this JsonSerializerSettings settings)
Used to ensure the static default serializer settings cannot be accidentally modified.
static JsonSerializerSettings GetJsonSerializerSettings(this JsonSerializer toCopy)
Get a new JsonSerializer with the same settings as this converter.
Utilities that reflect on a type or property expression.