|
| 1 | +// |
| 2 | +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 3 | +// |
| 4 | +using System; |
| 5 | +using System.Text; |
| 6 | +using System.Linq; |
| 7 | +using System.Text.Json.Serialization; |
| 8 | +using System.Collections.Generic; |
| 9 | +using Algolia.Search.Serializer; |
| 10 | +using System.Text.Json; |
| 11 | +using System.IO; |
| 12 | +using System.Reflection; |
| 13 | +using Algolia.Search.Models.Common; |
| 14 | + |
| 15 | +namespace Algolia.Search.Models.Search; |
| 16 | + |
| 17 | +/// <summary> |
| 18 | +/// BuiltInOperationValue |
| 19 | +/// </summary> |
| 20 | +[JsonConverter(typeof(BuiltInOperationValueJsonConverter))] |
| 21 | +public partial class BuiltInOperationValue : AbstractSchema |
| 22 | +{ |
| 23 | + /// <summary> |
| 24 | + /// Initializes a new instance of the BuiltInOperationValue class |
| 25 | + /// with a string |
| 26 | + /// </summary> |
| 27 | + /// <param name="actualInstance">An instance of string.</param> |
| 28 | + public BuiltInOperationValue(string actualInstance) |
| 29 | + { |
| 30 | + ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null."); |
| 31 | + } |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Initializes a new instance of the BuiltInOperationValue class |
| 35 | + /// with a int |
| 36 | + /// </summary> |
| 37 | + /// <param name="actualInstance">An instance of int.</param> |
| 38 | + public BuiltInOperationValue(int actualInstance) |
| 39 | + { |
| 40 | + ActualInstance = actualInstance; |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Gets or Sets ActualInstance |
| 46 | + /// </summary> |
| 47 | + public sealed override object ActualInstance { get; set; } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Get the actual instance of `string`. If the actual instance is not `string`, |
| 51 | + /// the InvalidClassException will be thrown |
| 52 | + /// </summary> |
| 53 | + /// <returns>An instance of string</returns> |
| 54 | + public string AsString() |
| 55 | + { |
| 56 | + return (string)ActualInstance; |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Get the actual instance of `int`. If the actual instance is not `int`, |
| 61 | + /// the InvalidClassException will be thrown |
| 62 | + /// </summary> |
| 63 | + /// <returns>An instance of int</returns> |
| 64 | + public int AsInt() |
| 65 | + { |
| 66 | + return (int)ActualInstance; |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Check if the actual instance is of `string` type. |
| 72 | + /// </summary> |
| 73 | + /// <returns>Whether or not the instance is the type</returns> |
| 74 | + public bool IsString() |
| 75 | + { |
| 76 | + return ActualInstance.GetType() == typeof(string); |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Check if the actual instance is of `int` type. |
| 81 | + /// </summary> |
| 82 | + /// <returns>Whether or not the instance is the type</returns> |
| 83 | + public bool IsInt() |
| 84 | + { |
| 85 | + return ActualInstance.GetType() == typeof(int); |
| 86 | + } |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// Returns the string presentation of the object |
| 90 | + /// </summary> |
| 91 | + /// <returns>String presentation of the object</returns> |
| 92 | + public override string ToString() |
| 93 | + { |
| 94 | + var sb = new StringBuilder(); |
| 95 | + sb.Append("class BuiltInOperationValue {\n"); |
| 96 | + sb.Append(" ActualInstance: ").Append(ActualInstance).Append("\n"); |
| 97 | + sb.Append("}\n"); |
| 98 | + return sb.ToString(); |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Returns the JSON string presentation of the object |
| 103 | + /// </summary> |
| 104 | + /// <returns>JSON string presentation of the object</returns> |
| 105 | + public override string ToJson() |
| 106 | + { |
| 107 | + return JsonSerializer.Serialize(ActualInstance, JsonConfig.Options); |
| 108 | + } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Returns true if objects are equal |
| 112 | + /// </summary> |
| 113 | + /// <param name="obj">Object to be compared</param> |
| 114 | + /// <returns>Boolean</returns> |
| 115 | + public override bool Equals(object obj) |
| 116 | + { |
| 117 | + if (obj is not BuiltInOperationValue input) |
| 118 | + { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + return ActualInstance.Equals(input.ActualInstance); |
| 123 | + } |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// Gets the hash code |
| 127 | + /// </summary> |
| 128 | + /// <returns>Hash code</returns> |
| 129 | + public override int GetHashCode() |
| 130 | + { |
| 131 | + unchecked // Overflow is fine, just wrap |
| 132 | + { |
| 133 | + int hashCode = 41; |
| 134 | + if (ActualInstance != null) |
| 135 | + hashCode = hashCode * 59 + ActualInstance.GetHashCode(); |
| 136 | + return hashCode; |
| 137 | + } |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +/// <summary> |
| 146 | +/// Custom JSON converter for BuiltInOperationValue |
| 147 | +/// </summary> |
| 148 | +public class BuiltInOperationValueJsonConverter : JsonConverter<BuiltInOperationValue> |
| 149 | +{ |
| 150 | + |
| 151 | + /// <summary> |
| 152 | + /// Check if the object can be converted |
| 153 | + /// </summary> |
| 154 | + /// <param name="objectType">Object type</param> |
| 155 | + /// <returns>True if the object can be converted</returns> |
| 156 | + public override bool CanConvert(Type objectType) |
| 157 | + { |
| 158 | + return objectType == typeof(BuiltInOperationValue); |
| 159 | + } |
| 160 | + |
| 161 | + /// <summary> |
| 162 | + /// To convert a JSON string into an object |
| 163 | + /// </summary> |
| 164 | + /// <param name="reader">JSON reader</param> |
| 165 | + /// <param name="typeToConvert">Object type</param> |
| 166 | + /// <param name="options">Serializer options</param> |
| 167 | + /// <returns>The object converted from the JSON string</returns> |
| 168 | + public override BuiltInOperationValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 169 | + { |
| 170 | + var jsonDocument = JsonDocument.ParseValue(ref reader); |
| 171 | + var root = jsonDocument.RootElement; |
| 172 | + if (root.ValueKind == JsonValueKind.String) |
| 173 | + { |
| 174 | + try |
| 175 | + { |
| 176 | + return new BuiltInOperationValue(jsonDocument.Deserialize<string>(JsonConfig.Options)); |
| 177 | + } |
| 178 | + catch (Exception exception) |
| 179 | + { |
| 180 | + // deserialization failed, try the next one |
| 181 | + System.Diagnostics.Debug.WriteLine($"Failed to deserialize into string: {exception}"); |
| 182 | + } |
| 183 | + } |
| 184 | + if (root.ValueKind == JsonValueKind.Number) |
| 185 | + { |
| 186 | + try |
| 187 | + { |
| 188 | + return new BuiltInOperationValue(jsonDocument.Deserialize<int>(JsonConfig.Options)); |
| 189 | + } |
| 190 | + catch (Exception exception) |
| 191 | + { |
| 192 | + // deserialization failed, try the next one |
| 193 | + System.Diagnostics.Debug.WriteLine($"Failed to deserialize into int: {exception}"); |
| 194 | + } |
| 195 | + } |
| 196 | + throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined."); |
| 197 | + } |
| 198 | + |
| 199 | + /// <summary> |
| 200 | + /// To write the JSON string |
| 201 | + /// </summary> |
| 202 | + /// <param name="writer">JSON writer</param> |
| 203 | + /// <param name="value">BuiltInOperationValue to be converted into a JSON string</param> |
| 204 | + /// <param name="options">JSON Serializer options</param> |
| 205 | + public override void Write(Utf8JsonWriter writer, BuiltInOperationValue value, JsonSerializerOptions options) |
| 206 | + { |
| 207 | + writer.WriteRawValue(value.ToJson()); |
| 208 | + } |
| 209 | +} |
| 210 | + |
0 commit comments