/* * InfluxDB OSS API Service * * The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. * * OpenAPI spec version: 2.0.0 * * Generated by: https://github.com/openapitools/openapi-generator.git */ using System; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using OpenAPIDateConverter = InfluxDB.Client.Api.Client.OpenAPIDateConverter; namespace InfluxDB.Client.Api.Domain { /// /// A set of statements /// [DataContract] public partial class Block : Node, IEquatable { /// /// Initializes a new instance of the class. /// /// Type of AST node. /// Block body. public Block(string type = default, List body = default) : base() { Type = type; Body = body; } /// /// Type of AST node /// /// Type of AST node [DataMember(Name = "type", EmitDefaultValue = false)] public string Type { get; set; } /// /// Block body /// /// Block body [DataMember(Name = "body", EmitDefaultValue = false)] [JsonConverter(typeof(BlockBodyAdapter))] public List Body { get; set; } /// /// Returns the string presentation of the object /// /// String presentation of the object public override string ToString() { var sb = new StringBuilder(); sb.Append("class Block {\n"); sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); sb.Append(" Type: ").Append(Type).Append("\n"); sb.Append(" Body: ").Append(Body).Append("\n"); sb.Append("}\n"); return sb.ToString(); } /// /// Returns the JSON string presentation of the object /// /// JSON string presentation of the object public override string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } /// /// Returns true if objects are equal /// /// Object to be compared /// Boolean public override bool Equals(object input) { return Equals(input as Block); } /// /// Returns true if Block instances are equal /// /// Instance of Block to be compared /// Boolean public bool Equals(Block input) { if (input == null) { return false; } return base.Equals(input) && ( Type == input.Type || Type != null && Type.Equals(input.Type) ) && base.Equals(input) && ( Body == input.Body || Body != null && Body.SequenceEqual(input.Body) ); } /// /// Gets the hash code /// /// Hash code public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = base.GetHashCode(); if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Body != null) { hashCode = hashCode * 59 + Body.GetHashCode(); } return hashCode; } } public class BlockBodyAdapter : JsonConverter { private static readonly Dictionary Types = new Dictionary(new Client.DiscriminatorComparer()) { { new[] { "BadStatement" }, typeof(BadStatement) }, { new[] { "VariableAssignment" }, typeof(VariableAssignment) }, { new[] { "MemberAssignment" }, typeof(MemberAssignment) }, { new[] { "ExpressionStatement" }, typeof(ExpressionStatement) }, { new[] { "ReturnStatement" }, typeof(ReturnStatement) }, { new[] { "OptionStatement" }, typeof(OptionStatement) }, { new[] { "BuiltinStatement" }, typeof(BuiltinStatement) }, { new[] { "TestStatement" }, typeof(TestStatement) } }; public override bool CanConvert(Type objectType) { return false; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { serializer.Serialize(writer, value); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return Deserialize(reader, objectType, serializer); } private object Deserialize(JsonReader reader, Type objectType, JsonSerializer serializer) { switch (reader.TokenType) { case JsonToken.StartObject: var jObject = Newtonsoft.Json.Linq.JObject.Load(reader); var discriminator = new[] { "type" }.Select(key => jObject[key].ToString()).ToArray(); Types.TryGetValue(discriminator, out var type); return serializer.Deserialize(jObject.CreateReader(), type); case JsonToken.StartArray: return DeserializeArray(reader, objectType, serializer); default: return serializer.Deserialize(reader, objectType); } } private IList DeserializeArray(JsonReader reader, Type targetType, JsonSerializer serializer) { var elementType = targetType.GenericTypeArguments.FirstOrDefault(); var list = (IList)Activator.CreateInstance(targetType); while (reader.Read() && reader.TokenType != JsonToken.EndArray) list.Add(Deserialize(reader, elementType, serializer)); return list; } } } }