2using System.Linq.Expressions;
3using System.Reflection;
30 CloningSerializer.SerializerSettings.ContractResolver =
35 CloningSerializer.SerializerSettings.NullValueHandling = NullValueHandling.Include;
36 CloningSerializer.DeserializerSettings.NullValueHandling = NullValueHandling.Include;
51 return obj.ShallowCopy<T>();
67 string serializedObj = CloningSerializer.Serialize(obj);
68 if (typeof(T) == obj.GetType())
69 return CloningSerializer.Deserialize<T>(serializedObj);
72 return (T)CloningSerializer.Deserialize(serializedObj, obj.GetType());
89 bool includeServerGeneratedProperties =
true,
bool includeNullProperties =
false)
91 if(includeServerGeneratedProperties && includeNullProperties)
92 return CloningSerializer.Serialize(obj, pretty);
93 if (!includeServerGeneratedProperties && !includeNullProperties)
96 if(includeServerGeneratedProperties)
97 converter.SerializerSettings.ContractResolver =
99 if (includeNullProperties)
101 converter.SerializerSettings.NullValueHandling = NullValueHandling.Include;
102 converter.DeserializerSettings.NullValueHandling = NullValueHandling.Include;
118 this T obj, Expression<Func<T, TProperty>> propertyExpression, TProperty newValue)
121 PropertyInfo property;
127 propertyName =
property.Name;
131 throw new ArgumentException($
"Error: Invalid property expression: {propertyExpression}", ex);
135 Type runtimeType = obj.GetType();
136 Type declaringType =
property.DeclaringType;
137 if (runtimeType != declaringType)
138 property = runtimeType.GetProperty(propertyName);
139 if (property ==
null)
140 throw new ArgumentException($
"The property {propertyName} defined on the type " +
141 $
"{declaringType.NiceTypeName()} could not be found on the object " +
142 $
"supplied with the instance type {runtimeType.NiceTypeName()}");
146 property.SetValue(obj, newValue,
null);
150 throw new ArgumentException(
"The supplied value of type " +
151 $
"{newValue?.GetType().NiceTypeName() ?? "(
null)
"} is invalid for the " +
152 $
"property {propertyName} on the type {runtimeType.NiceTypeName()}. " +
153 $
"The expected type is {property.PropertyType.NiceTypeName()}", ex);
Provides the REST request methods available to data endpoints.
static string Serialize(this IAPIType obj, bool pretty=false, bool includeServerGeneratedProperties=true, bool includeNullProperties=false)
Returns the JSON representation of the current object.
static T DeepCopy< T >(this T obj)
Creates a clone of this object by serializing to JSON and then deserializing it to a new object....
static T ShallowCopy< T >(this T obj)
Makes a shallow copy of this object.
static T Change< T, TProperty >(this T obj, Expression< Func< T, TProperty > > propertyExpression, TProperty newValue)
Changes the specified property on the object (using reflection) and then returns the modified object.
A pre-configured RestSharp serializer / deserializer which is made to support parsing of AnalyzeRe AP...
static readonly AnalyzeReJsonConverter Default
Returns the default AnalyzeReJsonConverter instance.
string Serialize(object obj)
Serialize the object as JSON.
A custom property contract resolver which allows Server-Generated Analyze Re properties (ServerGenera...
Utilities that reflect on a type or property expression.
Interface shared by all object types and resources returned by the Analyze Re server.