openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Generated/Models/AssistantDeletionResult.Serialization.cs
167lines · modecode
| 1 | // <auto-generated/> |
| 2 | |
| 3 | #nullable disable |
| 4 | |
| 5 | using System; |
| 6 | using System.ClientModel; |
| 7 | using System.ClientModel.Primitives; |
| 8 | using System.Collections.Generic; |
| 9 | using System.Text.Json; |
| 10 | using OpenAI; |
| 11 | |
| 12 | namespace OpenAI.Assistants |
| 13 | { |
| 14 | public partial class AssistantDeletionResult : IJsonModel<AssistantDeletionResult> |
| 15 | { |
| 16 | internal AssistantDeletionResult() |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | void IJsonModel<AssistantDeletionResult>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 21 | { |
| 22 | writer.WriteStartObject(); |
| 23 | JsonModelWriteCore(writer, options); |
| 24 | writer.WriteEndObject(); |
| 25 | } |
| 26 | |
| 27 | protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 28 | { |
| 29 | string format = options.Format == "W" ? ((IPersistableModel<AssistantDeletionResult>)this).GetFormatFromOptions(options) : options.Format; |
| 30 | if (format != "J") |
| 31 | { |
| 32 | throw new FormatException($"The model {nameof(AssistantDeletionResult)} does not support writing '{format}' format."); |
| 33 | } |
| 34 | if (_additionalBinaryDataProperties?.ContainsKey("deleted") != true) |
| 35 | { |
| 36 | writer.WritePropertyName("deleted"u8); |
| 37 | writer.WriteBooleanValue(Deleted); |
| 38 | } |
| 39 | if (_additionalBinaryDataProperties?.ContainsKey("id") != true) |
| 40 | { |
| 41 | writer.WritePropertyName("id"u8); |
| 42 | writer.WriteStringValue(AssistantId); |
| 43 | } |
| 44 | if (_additionalBinaryDataProperties?.ContainsKey("object") != true) |
| 45 | { |
| 46 | writer.WritePropertyName("object"u8); |
| 47 | writer.WriteStringValue(this.Object.ToString()); |
| 48 | } |
| 49 | if (true && _additionalBinaryDataProperties != null) |
| 50 | { |
| 51 | foreach (var item in _additionalBinaryDataProperties) |
| 52 | { |
| 53 | if (ModelSerializationExtensions.IsSentinelValue(item.Value)) |
| 54 | { |
| 55 | continue; |
| 56 | } |
| 57 | writer.WritePropertyName(item.Key); |
| 58 | #if NET6_0_OR_GREATER |
| 59 | writer.WriteRawValue(item.Value); |
| 60 | #else |
| 61 | using (JsonDocument document = JsonDocument.Parse(item.Value)) |
| 62 | { |
| 63 | JsonSerializer.Serialize(writer, document.RootElement); |
| 64 | } |
| 65 | #endif |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | AssistantDeletionResult IJsonModel<AssistantDeletionResult>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); |
| 71 | |
| 72 | protected virtual AssistantDeletionResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) |
| 73 | { |
| 74 | string format = options.Format == "W" ? ((IPersistableModel<AssistantDeletionResult>)this).GetFormatFromOptions(options) : options.Format; |
| 75 | if (format != "J") |
| 76 | { |
| 77 | throw new FormatException($"The model {nameof(AssistantDeletionResult)} does not support reading '{format}' format."); |
| 78 | } |
| 79 | using JsonDocument document = JsonDocument.ParseValue(ref reader); |
| 80 | return DeserializeAssistantDeletionResult(document.RootElement, options); |
| 81 | } |
| 82 | |
| 83 | internal static AssistantDeletionResult DeserializeAssistantDeletionResult(JsonElement element, ModelReaderWriterOptions options) |
| 84 | { |
| 85 | if (element.ValueKind == JsonValueKind.Null) |
| 86 | { |
| 87 | return null; |
| 88 | } |
| 89 | bool deleted = default; |
| 90 | string assistantId = default; |
| 91 | InternalDeleteAssistantResponseObject @object = default; |
| 92 | IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>(); |
| 93 | foreach (var prop in element.EnumerateObject()) |
| 94 | { |
| 95 | if (prop.NameEquals("deleted"u8)) |
| 96 | { |
| 97 | deleted = prop.Value.GetBoolean(); |
| 98 | continue; |
| 99 | } |
| 100 | if (prop.NameEquals("id"u8)) |
| 101 | { |
| 102 | assistantId = prop.Value.GetString(); |
| 103 | continue; |
| 104 | } |
| 105 | if (prop.NameEquals("object"u8)) |
| 106 | { |
| 107 | @object = new InternalDeleteAssistantResponseObject(prop.Value.GetString()); |
| 108 | continue; |
| 109 | } |
| 110 | if (true) |
| 111 | { |
| 112 | additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); |
| 113 | } |
| 114 | } |
| 115 | return new AssistantDeletionResult(deleted, assistantId, @object, additionalBinaryDataProperties); |
| 116 | } |
| 117 | |
| 118 | BinaryData IPersistableModel<AssistantDeletionResult>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); |
| 119 | |
| 120 | protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) |
| 121 | { |
| 122 | string format = options.Format == "W" ? ((IPersistableModel<AssistantDeletionResult>)this).GetFormatFromOptions(options) : options.Format; |
| 123 | switch (format) |
| 124 | { |
| 125 | case "J": |
| 126 | return ModelReaderWriter.Write(this, options); |
| 127 | default: |
| 128 | throw new FormatException($"The model {nameof(AssistantDeletionResult)} does not support writing '{options.Format}' format."); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | AssistantDeletionResult IPersistableModel<AssistantDeletionResult>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); |
| 133 | |
| 134 | protected virtual AssistantDeletionResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) |
| 135 | { |
| 136 | string format = options.Format == "W" ? ((IPersistableModel<AssistantDeletionResult>)this).GetFormatFromOptions(options) : options.Format; |
| 137 | switch (format) |
| 138 | { |
| 139 | case "J": |
| 140 | using (JsonDocument document = JsonDocument.Parse(data)) |
| 141 | { |
| 142 | return DeserializeAssistantDeletionResult(document.RootElement, options); |
| 143 | } |
| 144 | default: |
| 145 | throw new FormatException($"The model {nameof(AssistantDeletionResult)} does not support reading '{options.Format}' format."); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | string IPersistableModel<AssistantDeletionResult>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; |
| 150 | |
| 151 | public static implicit operator BinaryContent(AssistantDeletionResult assistantDeletionResult) |
| 152 | { |
| 153 | if (assistantDeletionResult == null) |
| 154 | { |
| 155 | return null; |
| 156 | } |
| 157 | return BinaryContent.Create(assistantDeletionResult, ModelSerializationExtensions.WireOptions); |
| 158 | } |
| 159 | |
| 160 | public static explicit operator AssistantDeletionResult(ClientResult result) |
| 161 | { |
| 162 | using PipelineResponse response = result.GetRawResponse(); |
| 163 | using JsonDocument document = JsonDocument.Parse(response.Content); |
| 164 | return DeserializeAssistantDeletionResult(document.RootElement, ModelSerializationExtensions.WireOptions); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |