|
| 1 | +// <auto-generated/> |
| 2 | + |
| 3 | +#nullable disable |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.ClientModel.Primitives; |
| 7 | +using System.Text.Json; |
| 8 | +using Sample; |
| 9 | + |
| 10 | +namespace Sample.Models |
| 11 | +{ |
| 12 | + [global::System.ClientModel.Primitives.PersistableModelProxyAttribute(typeof(global::Sample.Models.UnknownBaseModel))] |
| 13 | + public abstract partial class BaseModel : global::System.ClientModel.Primitives.IJsonModel<global::Sample.Models.BaseModel> |
| 14 | + { |
| 15 | + protected virtual global::Sample.Models.BaseModel PersistableModelCreateCore(global::System.BinaryData data, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 16 | + { |
| 17 | + string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>)this).GetFormatFromOptions(options) : options.Format; |
| 18 | + switch (format) |
| 19 | + { |
| 20 | + case "J": |
| 21 | + using (global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(data, global::Sample.ModelSerializationExtensions.JsonDocumentOptions)) |
| 22 | + { |
| 23 | + return global::Sample.Models.BaseModel.DeserializeBaseModel(document.RootElement, options); |
| 24 | + } |
| 25 | + default: |
| 26 | + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.BaseModel)} does not support reading '{options.Format}' format."); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + protected virtual global::System.BinaryData PersistableModelWriteCore(global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 31 | + { |
| 32 | + string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>)this).GetFormatFromOptions(options) : options.Format; |
| 33 | + switch (format) |
| 34 | + { |
| 35 | + case "J": |
| 36 | + return global::System.ClientModel.Primitives.ModelReaderWriter.Write(this, options, global::Sample.SampleContext.Default); |
| 37 | + default: |
| 38 | + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.BaseModel)} does not support writing '{options.Format}' format."); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + global::System.BinaryData global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>.Write(global::System.ClientModel.Primitives.ModelReaderWriterOptions options) => this.PersistableModelWriteCore(options); |
| 43 | + |
| 44 | + global::Sample.Models.BaseModel global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>.Create(global::System.BinaryData data, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) => this.PersistableModelCreateCore(data, options); |
| 45 | + |
| 46 | + string global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>.GetFormatFromOptions(global::System.ClientModel.Primitives.ModelReaderWriterOptions options) => "J"; |
| 47 | + |
| 48 | + void global::System.ClientModel.Primitives.IJsonModel<global::Sample.Models.BaseModel>.Write(global::System.Text.Json.Utf8JsonWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 49 | + { |
| 50 | + writer.WriteStartObject(); |
| 51 | + this.JsonModelWriteCore(writer, options); |
| 52 | + writer.WriteEndObject(); |
| 53 | + } |
| 54 | + |
| 55 | + protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 56 | + { |
| 57 | + string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>)this).GetFormatFromOptions(options) : options.Format; |
| 58 | + if ((format != "J")) |
| 59 | + { |
| 60 | + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.BaseModel)} does not support writing '{format}' format."); |
| 61 | + } |
| 62 | + writer.WritePropertyName("kind"u8); |
| 63 | + writer.WriteStringValue(Kind); |
| 64 | + if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) |
| 65 | + { |
| 66 | + foreach (var item in _additionalBinaryDataProperties) |
| 67 | + { |
| 68 | + writer.WritePropertyName(item.Key); |
| 69 | +#if NET6_0_OR_GREATER |
| 70 | + writer.WriteRawValue(item.Value); |
| 71 | +#else |
| 72 | + using (global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(item.Value)) |
| 73 | + { |
| 74 | + global::System.Text.Json.JsonSerializer.Serialize(writer, document.RootElement); |
| 75 | + } |
| 76 | +#endif |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + global::Sample.Models.BaseModel global::System.ClientModel.Primitives.IJsonModel<global::Sample.Models.BaseModel>.Create(ref global::System.Text.Json.Utf8JsonReader reader, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) => this.JsonModelCreateCore(ref reader, options); |
| 82 | + |
| 83 | + protected virtual global::Sample.Models.BaseModel JsonModelCreateCore(ref global::System.Text.Json.Utf8JsonReader reader, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 84 | + { |
| 85 | + string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.BaseModel>)this).GetFormatFromOptions(options) : options.Format; |
| 86 | + if ((format != "J")) |
| 87 | + { |
| 88 | + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.BaseModel)} does not support reading '{format}' format."); |
| 89 | + } |
| 90 | + using global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.ParseValue(ref reader); |
| 91 | + return global::Sample.Models.BaseModel.DeserializeBaseModel(document.RootElement, options); |
| 92 | + } |
| 93 | + |
| 94 | + internal static global::Sample.Models.BaseModel DeserializeBaseModel(global::System.Text.Json.JsonElement element, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) |
| 95 | + { |
| 96 | + if ((element.ValueKind == global::System.Text.Json.JsonValueKind.Null)) |
| 97 | + { |
| 98 | + return null; |
| 99 | + } |
| 100 | + if (element.TryGetProperty("kind"u8, out global::System.Text.Json.JsonElement discriminator)) |
| 101 | + { |
| 102 | + switch (discriminator.GetString()) |
| 103 | + { |
| 104 | + case "one": |
| 105 | + return global::Sample.Models.DerivedModel.DeserializeDerivedModel(element, options); |
| 106 | + } |
| 107 | + } |
| 108 | + return global::Sample.Models.UnknownBaseModel.DeserializeUnknownBaseModel(element, options); |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments