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