2using System.Collections.Concurrent;
4using System.Reflection;
9using Newtonsoft.Json.Linq;
17 #region Configuration Options
41 #endregion Configuration Options
55 #endregion Constructor
70 #region Public Methods
79 return CanConvertCache.GetOrAdd(
objectType, type =>
93 value = token.Type == JTokenType.Null ?
null :
94 token.Type == JTokenType.String ?
token.Value<
string>() :
96 $"to be a JSON \"string\" but a {token.Type.ToString()} was returned ({token})");
141 !String.IsNullOrEmpty(
strType))
150 else if (!String.IsNullOrEmpty(
strHref))
173 referenceType.NiceTypeName() +
"' did not match the expected type: '" +
183 throw new Exception(
"Missing Reference Constructor " +
198 throw new Exception(
"Could not find a constructor for '" +
199 referenceType.NiceTypeName() +
"' taking a parameter of type '" +
226 $"Unexpected non-Reference value: {value}");
252 #endregion Public Methods
Base class used by all types and resources.
Describes a collection of resources which can be listed.
Json converter helper class.
static JsonReader CopyReaderForObject(JsonReader reader, JObject jObject)
Creates a new reader for the specified jObject by copying the settings from an existing reader.
Deserializes AnalyzeRe API Reference objects to a new instance of a the target generic Reference type...
override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Serializes a Reference object based on the configured SerializationMethod controlling whether/when re...
ReferenceSerializationMethod SerializationMethod
Used during serialization to determine whether references should be expanded in JSON.
override bool CanConvert(Type objectType)
Determines if this converter is designed for deserialization to objects of the specified type.
ReferenceSerializationMethod
The SerializationMethod to use when serializing references.
@ UseReferencesOnly
Use the JSON representation of a reference to the object.
@ ExpandReferenceValues
Retrieve the referenced object and serialize it in place of the reference.
@ ExpandIfResolved
Serialize the referenced object only if it has already been retrieved.
override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
Parses the json to the specified type.
ReferenceConverter(ReferenceSerializationMethod serializationMethod=ReferenceSerializationMethod.UseReferencesOnly)
Initializes the ReferenceConverter using the specified SerializationMethod.
Implements the reference entity interface, with support for resolving references using lazy loading.
Utility for resolving types given only the types name (Useful for parsing ambiguous JSON objects).
static Type ResolveBaseTypeByURL(string href)
Get the base type of object referenced by the supplied server URL.
static bool ResolveTypeByName(string typeName, out Type resolvedType, Type requiredBaseType=null)
Clever method that checks all assemblies in the application being compiled for the type referenced by...
static Type GetGenericCovariantBase(Type T)
Returns the most strongly typed covariant base type which is assignable from the specified type T.
Interface for Base class used by all resources.
Base interface for all reference entities.
string ref_id
The id of the object being referred to.
string reference_type
In cases where a model can reference resources belonging to one of a number of collections,...
string href
The HREF that can be used to retrieve the object being referred to.