C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
LayerViewCreationConverter.cs
Go to the documentation of this file.
1using System;
4using Newtonsoft.Json.Linq;
5
7{
14 {
15 #region Constants
16 private const string LayerPropertyName = nameof(ILayerView.layer);
17 private const string LayerTypePropertyName = APIType_Polymorphic.TypePropertyName;
18 #endregion Constants
19
34 protected override ILayerView Create(Type objectType, JObject jObject)
35 {
36 // If the requested objectType is not an interface (i.e. ILayerview<...>)
37 // and is instead an instantiable object type (LayerView<ILayer>), then
38 // it is incorrect for us to create an object that is type specific, such
39 // as LayerView<CatXL> as that is covariantly incompatible.
40 // So just instantiate the specified type.
41 if (!objectType.IsInterface && !objectType.IsAbstract)
42 return (ILayerView)Activator.CreateInstance(objectType);
43
44 JToken layer = jObject[LayerPropertyName];
45 if (layer == null)
47 "Could not parse this LayerView object because " +
48 "it is missing the '" + LayerPropertyName + "' property");
49 string layerTypeName = (layer[LayerTypePropertyName] ?? "").ToString();
50 if (String.IsNullOrEmpty(layerTypeName))
52 "Could not parse this LayerView because it's layer " +
53 "does not specify the '" + layerTypeName + "' property");
54
56 return (ILayerView)Activator.CreateInstance(
57 typeof(LayerView<>).MakeGenericTypeFast(resolvedLayerType));
58 throw new InvalidOperationException("The server returned an " +
59 "unrecognized layer sub-type: \"" + layerTypeName + "\".");
60 }
61 }
62}
Base class used by all types and resources.
Describes a collection of resources which can be listed.
Allows serializing and deserializing derived AnalyzeRe Resource Views to a target base type....
override ILayerView Create(Type objectType, JObject jObject)
Create a new instance of the requested resource type for deserialization of a JSON string.
Utility for resolving types given only the types name (Useful for parsing ambiguous JSON objects).
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...
Represents the Analysis of a Layer.
ILayer layer
The layer contained in this LayerView.
Definition ILayerView.cs:12
Abstract representation of a layer.
Definition ILayer.cs:7