This commit is contained in:
Pavel Krymets 2020-01-02 16:10:08 -08:00 коммит произвёл GitHub
Родитель 1808438ace
Коммит 72725c100a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
111 изменённых файлов: 7055 добавлений и 403 удалений

5
.gitattributes поставляемый
Просмотреть файл

@ -1 +1,4 @@
* text=auto
* text=auto
**/Generated/**/*.cs linguist-generated=true
**/Generated/**/*.csproj linguist-generated=true

Просмотреть файл

@ -86,7 +86,7 @@ $testNames = if ($name) { $name } else
#'subscriptionId-apiVersion',
'url',
'validation',
#'xml-service',
'xml-service',
#'xms-error-responses',
'url-multi-collectionFormat'
}

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Pipeline.Generated;
using AutoRest.CSharp.V3.Plugins;
using AutoRest.CSharp.V3.Utilities;
@ -65,6 +66,8 @@ namespace AutoRest.CSharp.V3.ClientModels
private static ClientMethod? BuildMethod(Operation operation, Dictionary<string, ServiceClientParameter> clientParameters)
{
var httpRequest = operation.Request.Protocol.Http as HttpRequest;
var httpRequestWithBody = httpRequest as HttpWithBodyRequest;
//TODO: Handle multiple responses
var response = operation.Responses.FirstOrDefault();
var httpResponse = response?.Protocol.Http as HttpResponse;
@ -80,7 +83,7 @@ namespace AutoRest.CSharp.V3.ClientModels
List<RequestHeader> headers = new List<RequestHeader>();
List<ServiceClientParameter> methodParameters = new List<ServiceClientParameter>();
JsonRequestBody? body = null;
ObjectRequestBody? body = null;
foreach (Parameter requestParameter in operation.Request.Parameters ?? Array.Empty<Parameter>())
{
string defaultName = requestParameter.Language.Default.Name;
@ -130,7 +133,10 @@ namespace AutoRest.CSharp.V3.ClientModels
pathParameters.Add(serializedName, new PathSegment(constantOrParameter, true, serializationFormat));
break;
case ParameterLocation.Body:
body = new JsonRequestBody(constantOrParameter, ClientModelBuilderHelpers.CreateSerialization(requestParameter.Schema, requestParameter.IsNullable()));
Debug.Assert(httpRequestWithBody != null);
var serialization = SerializationBuilder.Build(httpRequestWithBody.KnownMediaType, requestParameter.Schema, requestParameter.IsNullable());
body = new ObjectRequestBody(constantOrParameter, serialization);
break;
case ParameterLocation.Uri:
uriParameters[defaultName] = constantOrParameter;
@ -140,9 +146,9 @@ namespace AutoRest.CSharp.V3.ClientModels
}
if (httpRequest is HttpWithBodyRequest httpWithBodyRequest)
if (httpRequestWithBody != null)
{
headers.AddRange(httpWithBodyRequest.MediaTypes.Select(mediaType => new RequestHeader("Content-Type", ClientModelBuilderHelpers.StringConstant(mediaType))));
headers.AddRange(httpRequestWithBody.MediaTypes.Select(mediaType => new RequestHeader("Content-Type", ClientModelBuilderHelpers.StringConstant(mediaType))));
}
var request = new ClientMethodRequest(
@ -159,7 +165,10 @@ namespace AutoRest.CSharp.V3.ClientModels
{
var schema = schemaResponse.Schema is ConstantSchema constantSchema ? constantSchema.ValueType : schemaResponse.Schema;
var responseType = ClientModelBuilderHelpers.CreateType(schema, isNullable: false);
responseBody = new JsonResponseBody(responseType, ClientModelBuilderHelpers.CreateSerialization(schema, false));
ObjectSerialization serialization = SerializationBuilder.Build(httpResponse.KnownMediaType, schema, isNullable: false);
responseBody = new ObjectResponseBody(responseType, serialization);
}
else if (response is BinaryResponse)
{

Просмотреть файл

@ -7,7 +7,7 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal class ClientMethodRequest
{
public ClientMethodRequest(RequestMethod method, ConstantOrParameter[] hostSegments, PathSegment[] pathSegments, QueryParameter[] query, RequestHeader[] headers, JsonRequestBody? body)
public ClientMethodRequest(RequestMethod method, ConstantOrParameter[] hostSegments, PathSegment[] pathSegments, QueryParameter[] query, RequestHeader[] headers, ObjectRequestBody? body)
{
Method = method;
HostSegments = hostSegments;
@ -22,6 +22,6 @@ namespace AutoRest.CSharp.V3.ClientModels
public PathSegment[] PathSegments { get; }
public QueryParameter[] Query { get; }
public RequestHeader[] Headers { get; }
public JsonRequestBody? Body { get; set; }
public ObjectRequestBody? Body { get; set; }
}
}

Просмотреть файл

@ -3,6 +3,7 @@
using System;
using System.Globalization;
using System.Xml;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Pipeline.Generated;
@ -91,27 +92,5 @@ namespace AutoRest.CSharp.V3.ClientModels
{
return ParseClientConstant(constant.Value.Value, CreateType(constant.ValueType, constant.Value.Value == null));
}
public static JsonSerialization CreateSerialization(Schema schema, bool isNullable)
{
switch (schema)
{
case ConstantSchema constantSchema:
return CreateSerialization(constantSchema.ValueType, constantSchema.Value.Value == null);
case ArraySchema arraySchema:
return new JsonArraySerialization(CreateType(arraySchema, false), CreateSerialization(arraySchema.ElementType, false));
case DictionarySchema dictionarySchema:
var dictionaryElementTypeReference = new DictionaryTypeReference(
new FrameworkTypeReference(typeof(string)),
CreateType(dictionarySchema.ElementType, false),
false);
return new JsonObjectSerialization(dictionaryElementTypeReference, Array.Empty<JsonPropertySerialization>(),
new JsonDynamicPropertiesSerialization(CreateSerialization(dictionarySchema.ElementType, false)));
default:
return new JsonValueSerialization(CreateType(schema, isNullable), GetSerializationFormat(schema));
}
}
}
}

Просмотреть файл

@ -9,21 +9,21 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal class ClientObject : ClientModel, ISchemaTypeProvider
{
public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable<ClientObjectProperty> properties, ClientObjectDiscriminator? discriminator, DictionaryTypeReference? implementsDictionary, JsonObjectSerialization serialization)
public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable<ClientObjectProperty> properties, ClientObjectDiscriminator? discriminator, DictionaryTypeReference? implementsDictionary, ObjectSerialization[] serializations)
{
Schema = schema;
Name = name;
Inherits = inherits;
Discriminator = discriminator;
ImplementsDictionary = implementsDictionary;
Serialization = serialization;
Serializations = serializations;
Properties = new List<ClientObjectProperty>(properties);
}
public override string Name { get; }
public Schema Schema { get; }
public SchemaTypeReference? Inherits { get; }
public JsonObjectSerialization Serialization { get; }
public ObjectSerialization[] Serializations { get; }
public IList<ClientObjectProperty> Properties { get; }
public ClientObjectDiscriminator? Discriminator { get; }
public DictionaryTypeReference? ImplementsDictionary { get; }

Просмотреть файл

@ -15,6 +15,13 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal class ModelBuilder
{
private readonly KnownMediaType[] _mediaTypes;
public ModelBuilder(KnownMediaType[] mediaTypes)
{
_mediaTypes = mediaTypes;
}
private static ClientModel BuildClientEnum(SealedChoiceSchema sealedChoiceSchema) => new ClientEnum(
sealedChoiceSchema,
sealedChoiceSchema.CSharpName(),
@ -26,7 +33,7 @@ namespace AutoRest.CSharp.V3.ClientModels
choiceSchema.Choices.Select(c => new ClientEnumValue(c.CSharpName(), ClientModelBuilderHelpers.StringConstant(c.Value))),
true);
private static ClientModel BuildClientObject(ObjectSchema objectSchema)
private ClientModel BuildClientObject(ObjectSchema objectSchema)
{
ClientTypeReference? inheritsFromTypeReference = null;
DictionarySchema? inheritedDictionarySchema = null;
@ -45,7 +52,6 @@ namespace AutoRest.CSharp.V3.ClientModels
}
List<ClientObjectProperty> properties = new List<ClientObjectProperty>();
List<JsonPropertySerialization> serializationProperties = new List<JsonPropertySerialization>();
foreach (Property property in objectSchema.Properties!)
{
@ -53,14 +59,6 @@ namespace AutoRest.CSharp.V3.ClientModels
properties.Add(clientObjectProperty);
}
foreach (var schema in EnumerateHierarchy(objectSchema))
{
foreach (Property property in schema.Properties!)
{
serializationProperties.Add(CreateSerialization(property));
}
}
Discriminator? schemaDiscriminator = objectSchema.Discriminator;
ClientObjectDiscriminator? discriminator = null;
@ -96,22 +94,13 @@ namespace AutoRest.CSharp.V3.ClientModels
properties.ToArray(),
discriminator,
inheritedDictionarySchema == null ? null : CreateDictionaryType(inheritedDictionarySchema),
new JsonObjectSerialization(schemaTypeReference, serializationProperties.ToArray(), CreateAdditionalProperties(objectSchema))
BuildSerializations(objectSchema)
);
}
private static JsonDynamicPropertiesSerialization? CreateAdditionalProperties(ObjectSchema objectSchema)
private ObjectSerialization[] BuildSerializations(ObjectSchema objectSchema)
{
var inheritedDictionarySchema = objectSchema.Parents!.All.OfType<DictionarySchema>().FirstOrDefault();
if (inheritedDictionarySchema == null)
{
return null;
}
return new JsonDynamicPropertiesSerialization(
ClientModelBuilderHelpers.CreateSerialization(inheritedDictionarySchema.ElementType, false)
);
return _mediaTypes.Select(type => SerializationBuilder.BuildObject(type, objectSchema, isNullable: false)).ToArray();
}
private static DictionaryTypeReference CreateDictionaryType(DictionarySchema inheritedDictionarySchema)
@ -122,28 +111,6 @@ namespace AutoRest.CSharp.V3.ClientModels
false);
}
private static IEnumerable<ObjectSchema> EnumerateHierarchy(ObjectSchema schema)
{
yield return schema;
foreach (ComplexSchema parent in schema.Parents!.All)
{
if (parent is ObjectSchema objectSchema)
{
yield return objectSchema;
}
}
}
private static JsonPropertySerialization CreateSerialization(Property property)
{
return new JsonPropertySerialization(
property.SerializedName,
property.CSharpName(),
ClientModelBuilderHelpers.CreateSerialization(property.Schema, property.IsNullable()),
ClientModelBuilderHelpers.CreateType(property.Schema, property.IsNullable())
);
}
private static ClientObjectDiscriminatorImplementation[] CreateDiscriminatorImplementations(Discriminator schemaDiscriminator)
{
return schemaDiscriminator.All.Select(implementation => new ClientObjectDiscriminatorImplementation(
@ -153,7 +120,7 @@ namespace AutoRest.CSharp.V3.ClientModels
)).ToArray();
}
public static ClientModel BuildModel(Schema schema) => schema switch
public ClientModel BuildModel(Schema schema) => schema switch
{
SealedChoiceSchema sealedChoiceSchema => BuildClientEnum(sealedChoiceSchema),
ChoiceSchema choiceSchema => BuildClientEnum(choiceSchema),

Просмотреть файл

@ -5,12 +5,12 @@ using AutoRest.CSharp.V3.ClientModels.Serialization;
namespace AutoRest.CSharp.V3.ClientModels
{
internal class JsonRequestBody
internal class ObjectRequestBody
{
public ConstantOrParameter Value { get; }
public JsonSerialization Serialization { get; }
public ObjectSerialization Serialization { get; }
public JsonRequestBody(ConstantOrParameter value, JsonSerialization serialization)
public ObjectRequestBody(ConstantOrParameter value, ObjectSerialization serialization)
{
Value = value;
Serialization = serialization;

Просмотреть файл

@ -5,15 +5,15 @@ using AutoRest.CSharp.V3.ClientModels.Serialization;
namespace AutoRest.CSharp.V3.ClientModels
{
internal class JsonResponseBody: ResponseBody
internal class ObjectResponseBody: ResponseBody
{
public JsonResponseBody(ClientTypeReference type, JsonSerialization serialization)
public ObjectResponseBody(ClientTypeReference type, ObjectSerialization serialization)
{
Serialization = serialization;
Type = type;
}
public JsonSerialization Serialization { get; }
public ObjectSerialization Serialization { get; }
public override ClientTypeReference Type { get; }
}
}

Просмотреть файл

@ -5,17 +5,15 @@ namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class JsonPropertySerialization
{
public JsonPropertySerialization(string name, string memberName, JsonSerialization valueSerialization, ClientTypeReference type)
public JsonPropertySerialization(string name, string memberName, JsonSerialization valueSerialization)
{
Name = name;
MemberName = memberName;
ValueSerialization = valueSerialization;
Type = type;
}
public string Name { get; }
public string MemberName { get; }
public ClientTypeReference Type { get; }
public JsonSerialization ValueSerialization { get; }
}
}

Просмотреть файл

@ -4,7 +4,7 @@
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal abstract class JsonSerialization
internal abstract class JsonSerialization: ObjectSerialization
{
public abstract ClientTypeReference Type { get; }
}

Просмотреть файл

@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal abstract class ObjectSerialization
{
}
}

Просмотреть файл

@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlArraySerialization : XmlElementSerialization
{
public XmlArraySerialization(ClientTypeReference type, XmlElementSerialization valueSerialization, string name, bool wrapped)
{
Type = type;
ValueSerialization = valueSerialization;
Name = name;
Wrapped = wrapped;
}
public override ClientTypeReference Type { get; }
public XmlElementSerialization ValueSerialization { get; }
public override string Name { get; }
public bool Wrapped { get; }
}
}

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlDictionarySerialization : XmlElementSerialization
{
public XmlDictionarySerialization(ClientTypeReference type, XmlElementSerialization valueSerialization, string name)
{
Type = type;
ValueSerialization = valueSerialization;
Name = name;
}
public override string Name { get; }
public override ClientTypeReference Type { get; }
public XmlElementSerialization ValueSerialization { get; }
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal abstract class XmlElementSerialization: ObjectSerialization
{
public abstract string Name { get; }
public abstract ClientTypeReference Type { get; }
}
}

Просмотреть файл

@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlElementValueSerialization: XmlElementSerialization
{
public XmlElementValueSerialization(string name, XmlValueSerialization value)
{
Name = name;
Value = value;
}
public override string Name { get; }
public override ClientTypeReference Type => Value.Type;
public XmlValueSerialization Value { get; }
}
}

Просмотреть файл

@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlObjectArraySerialization
{
public XmlObjectArraySerialization(string memberName, XmlArraySerialization arraySerialization)
{
MemberName = memberName;
ArraySerialization = arraySerialization;
}
public string MemberName { get; }
public XmlArraySerialization ArraySerialization { get; }
}
}

Просмотреть файл

@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlObjectAttributeSerialization
{
public XmlObjectAttributeSerialization(
string name,
string memberName,
XmlValueSerialization valueSerialization)
{
Name = name;
MemberName = memberName;
ValueSerialization = valueSerialization;
}
public string Name { get; }
public string MemberName { get; }
public ClientTypeReference Type => ValueSerialization.Type;
public XmlValueSerialization ValueSerialization { get; }
}
}

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlObjectElementSerialization
{
public XmlObjectElementSerialization(
string memberName,
XmlElementSerialization valueSerialization)
{
MemberName = memberName;
ValueSerialization = valueSerialization;
}
public string MemberName { get; }
public ClientTypeReference Type => ValueSerialization.Type;
public XmlElementSerialization ValueSerialization { get; }
}
}

Просмотреть файл

@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlObjectSerialization: XmlElementSerialization
{
public XmlObjectSerialization(string name,
ClientTypeReference type,
XmlObjectElementSerialization[] elements,
XmlObjectAttributeSerialization[] attributes,
XmlObjectArraySerialization[] embeddedArrays)
{
Type = type;
Elements = elements;
Attributes = attributes;
Name = name;
EmbeddedArrays = embeddedArrays;
}
public override string Name { get; }
public XmlObjectElementSerialization[] Elements { get; }
public XmlObjectAttributeSerialization[] Attributes { get; }
public XmlObjectArraySerialization[] EmbeddedArrays { get; }
public override ClientTypeReference Type { get; }
}
}

Просмотреть файл

@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace AutoRest.CSharp.V3.ClientModels.Serialization
{
internal class XmlValueSerialization
{
public XmlValueSerialization(ClientTypeReference type, SerializationFormat format)
{
Type = type;
Format = format;
}
public ClientTypeReference Type { get; }
public SerializationFormat Format { get; }
}
}

Просмотреть файл

@ -0,0 +1,197 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Pipeline.Generated;
using AutoRest.CSharp.V3.Plugins;
namespace AutoRest.CSharp.V3.ClientModels
{
internal class SerializationBuilder
{
public static ObjectSerialization BuildObject(KnownMediaType mediaType, ObjectSchema objectSchema, bool isNullable)
{
ClientTypeReference schemaTypeReference = ClientModelBuilderHelpers.CreateType(objectSchema, isNullable);
switch (mediaType)
{
case KnownMediaType.Json:
return BuildJsonObjectSerialization(objectSchema, schemaTypeReference, isNullable);
case KnownMediaType.Xml:
return BuildXmlObjectSerialization(objectSchema, schemaTypeReference, isNullable);
default:
throw new NotImplementedException(mediaType.ToString());
}
}
public static ObjectSerialization Build(KnownMediaType mediaType, Schema schema, bool isNullable)
{
switch (mediaType)
{
case KnownMediaType.Json:
return BuildSerialization(schema, isNullable);
case KnownMediaType.Xml:
return BuildXmlElementSerialization(schema, isNullable, schema.XmlName ?? schema.Name, true);
default:
throw new NotImplementedException(mediaType.ToString());
}
}
private static XmlElementSerialization BuildXmlElementSerialization(Schema schema, bool isNullable, string? name, bool isRoot)
{
string xmlName =
schema.XmlName ??
name ??
schema.Name;
switch (schema)
{
case ConstantSchema constantSchema:
return BuildXmlElementSerialization(constantSchema.ValueType, constantSchema.Value.Value == null, name, false);
case ArraySchema arraySchema:
var wrapped = isRoot || arraySchema.Serialization?.Xml?.Wrapped == true;
return new XmlArraySerialization(
ClientModelBuilderHelpers.CreateType(arraySchema, isNullable),
BuildXmlElementSerialization(arraySchema.ElementType, false, null, false),
xmlName,
wrapped);
case DictionarySchema dictionarySchema:
return new XmlDictionarySerialization(
ClientModelBuilderHelpers.CreateType(dictionarySchema, isNullable),
BuildXmlElementSerialization(dictionarySchema.ElementType, false, "!dictionary-item", false),
xmlName);
default:
return new XmlElementValueSerialization(xmlName, BuildXmlValueSerialization(schema, isNullable));
}
}
private static XmlValueSerialization BuildXmlValueSerialization(Schema schema, bool isNullable)
{
return new XmlValueSerialization(ClientModelBuilderHelpers.CreateType(schema, isNullable),
ClientModelBuilderHelpers.GetSerializationFormat(schema));
}
private static JsonSerialization BuildSerialization(Schema schema, bool isNullable)
{
switch (schema)
{
case ConstantSchema constantSchema:
return BuildSerialization(constantSchema.ValueType, constantSchema.Value.Value == null);
case ArraySchema arraySchema:
return new JsonArraySerialization(
ClientModelBuilderHelpers.CreateType(arraySchema, isNullable), BuildSerialization(arraySchema.ElementType, false));
case DictionarySchema dictionarySchema:
var dictionaryElementTypeReference = new DictionaryTypeReference(
new FrameworkTypeReference(typeof(string)),
ClientModelBuilderHelpers.CreateType(dictionarySchema.ElementType, false),
isNullable);
return new JsonObjectSerialization(dictionaryElementTypeReference, Array.Empty<JsonPropertySerialization>(),
new JsonDynamicPropertiesSerialization(BuildSerialization(dictionarySchema.ElementType, false)));
default:
return new JsonValueSerialization(
ClientModelBuilderHelpers.CreateType(schema, isNullable),
ClientModelBuilderHelpers.GetSerializationFormat(schema));
}
}
private static XmlObjectSerialization BuildXmlObjectSerialization(ObjectSchema objectSchema, ClientTypeReference schemaTypeReference, bool isNullable)
{
List<XmlObjectElementSerialization> elements = new List<XmlObjectElementSerialization>();
List<XmlObjectAttributeSerialization> attributes = new List<XmlObjectAttributeSerialization>();
List<XmlObjectArraySerialization> embeddedArrays = new List<XmlObjectArraySerialization>();
foreach (var schema in EnumerateHierarchy(objectSchema))
{
foreach (Property property in schema.Properties!)
{
var name = property.SerializedName;
var isAttribute = property.Schema.Serialization?.Xml?.Attribute == true;
if (isAttribute)
{
attributes.Add(
new XmlObjectAttributeSerialization(
name,
property.CSharpName(),
BuildXmlValueSerialization(property.Schema, property.IsNullable())
)
);
}
else
{
XmlElementSerialization valueSerialization = BuildXmlElementSerialization(property.Schema, property.IsNullable(), name, false);
if (valueSerialization is XmlArraySerialization arraySerialization)
{
embeddedArrays.Add(new XmlObjectArraySerialization(property.CSharpName(), arraySerialization));
}
else
{
elements.Add(
new XmlObjectElementSerialization(
property.CSharpName(),
valueSerialization
)
);
}
}
}
}
return new XmlObjectSerialization(
objectSchema.Serialization?.Xml?.Name ?? objectSchema.Language.Default.Name,
schemaTypeReference, elements.ToArray(), attributes.ToArray(), embeddedArrays.ToArray());
}
private static JsonObjectSerialization BuildJsonObjectSerialization(ObjectSchema objectSchema, ClientTypeReference schemaTypeReference, bool isNullable)
{
List<JsonPropertySerialization> serializationProperties = new List<JsonPropertySerialization>();
foreach (var schema in EnumerateHierarchy(objectSchema))
{
foreach (Property property in schema.Properties!)
{
JsonPropertySerialization propertySerialization = new JsonPropertySerialization(
property.SerializedName,
property.CSharpName(),
BuildSerialization(property.Schema, property.IsNullable())
);
serializationProperties.Add(propertySerialization);
}
}
return new JsonObjectSerialization(schemaTypeReference, serializationProperties.ToArray(), CreateAdditionalProperties(objectSchema));
}
private static IEnumerable<ObjectSchema> EnumerateHierarchy(ObjectSchema schema)
{
yield return schema;
foreach (ComplexSchema parent in schema.Parents!.All)
{
if (parent is ObjectSchema objectSchema)
{
yield return objectSchema;
}
}
}
private static JsonDynamicPropertiesSerialization? CreateAdditionalProperties(ObjectSchema objectSchema)
{
var inheritedDictionarySchema = objectSchema.Parents!.All.OfType<DictionarySchema>().FirstOrDefault();
if (inheritedDictionarySchema == null)
{
return null;
}
return new JsonDynamicPropertiesSerialization(
BuildSerialization(inheritedDictionarySchema.ElementType, false)
);
}
}
}

Просмотреть файл

@ -8,7 +8,9 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using AutoRest.CSharp.V3.ClientModels;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Utilities;
using Azure;
using Azure.Core;
@ -156,20 +158,34 @@ namespace AutoRest.CSharp.V3.CodeGen
WriteQueryParameter(writer, queryParameter);
}
if (operation.Request.Body is JsonRequestBody body)
if (operation.Request.Body is ObjectRequestBody body && body.Serialization is JsonSerialization jsonSerialization)
{
writer.Line($"using var content = new {writer.Type(typeof(Utf8JsonRequestContent))}();");
writer.Line($"using var content = new {typeof(Utf8JsonRequestContent)}();");
ConstantOrParameter value = body.Value;
writer.ToSerializeCall(
body.Serialization,
jsonSerialization,
_typeFactory,
w => WriteConstantOrParameter(w, value),
writerName: w => w.Append($"content.{nameof(Utf8JsonRequestContent.JsonWriter)}"));
writer.Line($"request.Content = content;");
}
else if (operation.Request.Body is ObjectRequestBody xmlBody && xmlBody.Serialization is XmlElementSerialization xmlSerialization)
{
writer.Line($"using var content = new {typeof(XmlWriterContent)}();");
ConstantOrParameter value = xmlBody.Value;
writer.ToSerializeCall(
xmlSerialization,
_typeFactory,
w => WriteConstantOrParameter(w, value),
writerName: w => w.Append($"content.{nameof(XmlWriterContent.XmlWriter)}"));
writer.Line($"request.Content = content;");
}
writer.Line($"await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);");
@ -352,18 +368,32 @@ namespace AutoRest.CSharp.V3.CodeGen
{
string valueVariable = "value";
if (responseBody is JsonResponseBody jsonResponseBody)
if (responseBody is ObjectResponseBody objectResponseBody)
{
writer.Line($"using var document = await {writer.Type(typeof(JsonDocument))}.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);");
writer.ToDeserializeCall(
jsonResponseBody.Serialization,
_typeFactory,
w => w.Append($"document.RootElement"),
ref valueVariable
);
const string document = "document";
switch (objectResponseBody.Serialization)
{
case JsonSerialization jsonSerialization:
writer.Line($"using var {document:D} = await {writer.Type(typeof(JsonDocument))}.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);");
writer.ToDeserializeCall(
jsonSerialization,
_typeFactory,
w => w.Append($"document.RootElement"),
ref valueVariable
);
break;
case XmlElementSerialization xmlSerialization:
writer.Line($"var {document:D} = {typeof(XDocument)}.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);");
writer.ToDeserializeCall(
xmlSerialization,
_typeFactory,
w => w.Append($"document"),
ref valueVariable
);
break;
}
}
if (responseBody is StreamResponseBody _)
else if (responseBody is StreamResponseBody _)
{
writer.Line($"var {valueVariable:D} = message.ExtractResponseContent();");
}

Просмотреть файл

@ -25,10 +25,15 @@ namespace AutoRest.CSharp.V3.CodeGen
_scopes.Push(new CodeWriterScope(this, ""));
}
public CodeWriterScope Scope(string start = "{", string end = "}")
public CodeWriterScope Scope(FormattableString line)
{
LineRaw(start);
CodeWriterScope codeWriterScope = new CodeWriterScope(this, end);
return Line(line).Scope();
}
public CodeWriterScope Scope()
{
LineRaw("{");
CodeWriterScope codeWriterScope = new CodeWriterScope(this, "}");
_scopes.Push(codeWriterScope);
return codeWriterScope;
}

Просмотреть файл

@ -8,7 +8,7 @@ using AutoRest.CSharp.V3.ClientModels.Serialization;
namespace AutoRest.CSharp.V3.CodeGen
{
internal static class JsonSerializerExtensions
internal static class JsonSerializerWriterExtensions
{
public static void ToSerializeCall(this CodeWriter writer, JsonSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate? writerName = null)
{
@ -41,7 +41,7 @@ namespace AutoRest.CSharp.V3.CodeGen
foreach (JsonPropertySerialization property in dictionary.Properties)
{
using (property.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default)
using (property.ValueSerialization.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default)
{
writer.Line($"{writerName}.WritePropertyName({property.Name:L});");
writer.ToSerializeCall(
@ -244,7 +244,7 @@ namespace AutoRest.CSharp.V3.CodeGen
private static void ReadProperty(CodeWriter writer, string itemVariable, CodeWriterDelegate destination, JsonPropertySerialization property, TypeFactory typeFactory)
{
var type = property.Type;
var type = property.ValueSerialization.Type;
var name = property.MemberName;
CSharpType propertyType = typeFactory.CreateType(type);
@ -261,7 +261,7 @@ namespace AutoRest.CSharp.V3.CodeGen
{
if (propertyType.IsNullable && (type is DictionaryTypeReference || type is CollectionTypeReference))
{
writer.Line($"{destination}.{name} = new {writer.Type(typeFactory.CreateConcreteType(property.Type))}();");
writer.Line($"{destination}.{name} = new {writer.Type(typeFactory.CreateConcreteType(property.ValueSerialization.Type))}();");
}
}

Просмотреть файл

@ -4,7 +4,10 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using AutoRest.CSharp.V3.ClientModels;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Plugins;
using Azure.Core;
@ -32,24 +35,77 @@ namespace AutoRest.CSharp.V3.CodeGen
}
}
//TODO: This is currently input schemas only. Does not handle output-style schemas.
private void WriteObjectSerialization(CodeWriter writer, ClientObject model)
{
if (!model.Serializations.Any())
{
return;
}
var cs = _typeFactory.CreateType(model);
using (writer.Namespace(cs.Namespace))
{
using (writer.Class(null, "partial", model.Name, writer.Type(typeof(IUtf8JsonSerializable))))
{
WriteSerialize(writer, model);
writer.Append($"public partial class {model.Name}: {typeof(IUtf8JsonSerializable)}");
WriteDeserialize(writer, model, cs);
if (model.Serializations.OfType<XmlElementSerialization>().Any())
{
writer.Append($", {typeof(IXmlSerializable)}");
}
using (writer.Scope())
{
foreach (var serialization in model.Serializations)
{
switch (serialization)
{
case JsonSerialization jsonSerialization:
WriteJsonSerialize(writer, model, jsonSerialization);
WriteJsonDeserialize(writer, model, jsonSerialization);
break;
case XmlElementSerialization xmlSerialization:
WriteXmlSerialize(writer, model, xmlSerialization);
WriteXmlDeserialize(writer, model, xmlSerialization);
break;
default:
throw new NotImplementedException(serialization.ToString());
}
}
}
}
}
private void WriteDeserialize(CodeWriter writer, ClientObject model, CSharpType cs)
private void WriteXmlSerialize(CodeWriter writer, ClientObject model, XmlElementSerialization serialization)
{
const string namehint = "nameHint";
writer.Append($"void {typeof(IXmlSerializable)}.{nameof(IXmlSerializable.Write)}({typeof(XmlWriter)} writer, {typeof(string)} {namehint})");
using (writer.Scope())
{
writer.ToSerializeCall(
serialization,
_typeFactory,
w => w.AppendRaw("this"),
null,
w => w.AppendRaw(namehint));
}
}
private void WriteXmlDeserialize(CodeWriter writer, ClientObject model, XmlElementSerialization serialization)
{
var cs = _typeFactory.CreateType(model);
var typeText = writer.Type(cs);
using (writer.Method("internal static", typeText, "Deserialize"+cs.Name, writer.Pair(typeof(XElement), "element")))
{
var resultVariable = "result";
writer.ToDeserializeCall(serialization,
_typeFactory,
w=> w.AppendRaw("element"), ref resultVariable, true);
writer.Line($"return {resultVariable};");
}
}
private void WriteJsonDeserialize(CodeWriter writer, ClientObject model, JsonSerialization jsonSerialization)
{
var cs = _typeFactory.CreateType(model);
var typeText = writer.Type(cs);
using (writer.Method("internal static", typeText, "Deserialize"+cs.Name, writer.Pair(typeof(JsonElement), "element")))
{
@ -72,17 +128,17 @@ namespace AutoRest.CSharp.V3.CodeGen
}
var resultVariable = "result";
writer.ToDeserializeCall(model.Serialization, _typeFactory, w=>w.AppendRaw("element"), ref resultVariable);
writer.ToDeserializeCall(jsonSerialization, _typeFactory, w=>w.AppendRaw("element"), ref resultVariable);
writer.Line($"return {resultVariable};");
}
}
private void WriteSerialize(CodeWriter writer, ClientObject model)
private void WriteJsonSerialize(CodeWriter writer, ClientObject model, JsonSerialization jsonSerialization)
{
writer.Append($"void {typeof(IUtf8JsonSerializable)}.{nameof(IUtf8JsonSerializable.Write)}({typeof(Utf8JsonWriter)} writer)");
using (writer.Scope())
{
writer.ToSerializeCall(model.Serialization, _typeFactory, w => w.AppendRaw("this"));
writer.ToSerializeCall(jsonSerialization, _typeFactory, w => w.AppendRaw("this"));
}
}

Просмотреть файл

@ -0,0 +1,387 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using AutoRest.CSharp.V3.ClientModels;
using AutoRest.CSharp.V3.ClientModels.Serialization;
using AutoRest.CSharp.V3.Utilities;
namespace AutoRest.CSharp.V3.CodeGen
{
internal static class XmlSerializerWriterExtensions
{
public static void ToSerializeCall(this CodeWriter writer, XmlElementSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate? writerName = null, CodeWriterDelegate? nameHint = null)
{
writerName ??= w => w.AppendRaw("writer");
switch (serialization)
{
case XmlArraySerialization array:
if (array.Wrapped)
{
writer.Line($"{writerName}.WriteStartElement({array.Name:L});");
}
var itemVariable = writer.GetTemporaryVariable("item");
using (writer.Scope($"foreach (var {itemVariable:D} in {name})"))
{
writer.ToSerializeCall(
array.ValueSerialization,
typeFactory,
w => w.Append($"{itemVariable}"),
writerName);
}
if (array.Wrapped)
{
writer.Line($"{writerName}.WriteEndElement();");
}
break;
case XmlDictionarySerialization dictionarySerialization:
var pairVariable = writer.GetTemporaryVariable("pair");
using (writer.Scope($"foreach (var {pairVariable:D} in {name})"))
{
writer.ToSerializeCall(
dictionarySerialization.ValueSerialization,
typeFactory,
w => w.Append($"{pairVariable}.Value"),
writerName);
}
break;
case XmlObjectSerialization objectSerialization:
if (nameHint != null)
{
writer.Line($"{writerName}.WriteStartElement({nameHint} ?? {objectSerialization.Name:L});");
}
else
{
writer.Line($"{writerName}.WriteStartElement({objectSerialization.Name:L});");
}
foreach (XmlObjectAttributeSerialization property in objectSerialization.Attributes)
{
using (property.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default)
{
writer.Line($"{writerName}.WriteStartAttribute({property.Name:L});");
writer.ToSerializeValueCall(
typeFactory,
w => w.Append($"{property.MemberName}"),
writerName,
property.ValueSerialization);
writer.Line($"{writerName}.WriteEndAttribute();");
}
}
foreach (XmlObjectElementSerialization property in objectSerialization.Elements)
{
using (property.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default)
{
writer.ToSerializeCall(
property.ValueSerialization,
typeFactory,
w => w.Append($"{property.MemberName}"));
}
}
foreach (XmlObjectArraySerialization property in objectSerialization.EmbeddedArrays)
{
using (property.ArraySerialization.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default)
{
writer.ToSerializeCall(
property.ArraySerialization,
typeFactory,
w => w.Append($"{property.MemberName}"));
}
}
writer.Line($"{writerName}.WriteEndElement();");
return;
case XmlElementValueSerialization elementValueSerialization:
var type = elementValueSerialization.Value.Type;
string elementName = elementValueSerialization.Name;
if ((type is SchemaTypeReference schemaReference && typeFactory.ResolveReference(schemaReference) is ClientObject) ||
(type is FrameworkTypeReference frameworkReference && frameworkReference.Type == typeof(object)))
{
writer.Line($"{writerName}.WriteObjectValue({name}, {elementName:L});");
return;
}
writer.Line($"{writerName}.WriteStartElement({elementName:L});");
writer.ToSerializeValueCall(typeFactory, name, writerName, elementValueSerialization.Value);
writer.Line($"{writerName}.WriteEndElement();");
return;
default:
throw new NotSupportedException();
}
}
private static void ToSerializeValueCall(this CodeWriter writer, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate writerName, XmlValueSerialization valueSerialization)
{
CSharpType implementationType = typeFactory.CreateType(valueSerialization.Type);
switch (valueSerialization.Type)
{
case SchemaTypeReference schemaTypeReference:
switch (typeFactory.ResolveReference(schemaTypeReference))
{
case ClientObject _:
throw new NotSupportedException("Object type references are only supported as elements");
case ClientEnum clientEnum:
writer.Append($"{writerName}.WriteValue({name}")
.AppendNullableValue(implementationType)
.AppendRaw(clientEnum.IsStringBased ? ".ToString()" : ".ToSerialString()")
.Line($");");
return;
}
return;
case FrameworkTypeReference frameworkTypeReference:
var frameworkType = frameworkTypeReference.Type;
if (frameworkType == typeof(object))
{
throw new NotSupportedException("Object references are only supported as elements");
}
bool writeFormat = frameworkType == typeof(byte[]) ||
frameworkType == typeof(DateTimeOffset) ||
frameworkType == typeof(DateTime) ||
frameworkType == typeof(TimeSpan);
writer.Append($"{writerName}.WriteValue({name}")
.AppendNullableValue(implementationType);
if (writeFormat && valueSerialization.Format.ToFormatSpecifier() is string formatString)
{
writer.Append($", {formatString:L}");
}
writer.LineRaw(");");
return;
default:
throw new NotSupportedException();
}
}
public static void ToDeserializeCall(this CodeWriter writer, XmlElementSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate element, ref string destination, bool isElement = false)
{
var type = serialization.Type;
destination = writer.GetTemporaryVariable(destination);
string s = destination;
writer
.Line($"{typeFactory.CreateType(type)} {destination:D} = default;");
if (isElement)
{
writer.ToDeserializeElementCall(serialization, typeFactory, w => w.AppendRaw(s), element);
}
else
{
writer.ToDeserializeCall(serialization, typeFactory, w => w.AppendRaw(s), element);
}
}
private static void ToDeserializeCall(this CodeWriter writer, XmlElementSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate destination, CodeWriterDelegate element)
{
if (serialization is XmlArraySerialization arraySerialization && !arraySerialization.Wrapped)
{
writer.ToDeserializeElementCall(serialization, typeFactory, destination, element);
return;
}
string elementVariable = writer.GetTemporaryVariable(serialization.Name.ToVariableName());
writer.Line($"var {elementVariable:D} = {element}.Element({serialization.Name:L});");
element = w => w.AppendRaw(elementVariable);
using (writer.Scope($"if ({elementVariable} != null)"))
{
writer.ToDeserializeElementCall(serialization, typeFactory, destination, element);
}
}
private static void ToDeserializeElementCall(this CodeWriter writer, XmlElementSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate destination, CodeWriterDelegate element, bool isElement = false)
{
switch (serialization)
{
case XmlArraySerialization arraySerialization:
{
string childElementVariable = writer.GetTemporaryVariable("e");
writer.Line($"{destination} = new {typeFactory.CreateConcreteType(serialization.Type)}();");
using (writer.Scope($"foreach (var {childElementVariable:D} in {element}.Elements({arraySerialization.ValueSerialization.Name:L}))"))
{
var itemVariableName = writer.GetTemporaryVariable("value");
writer.ToDeserializeCall(
arraySerialization.ValueSerialization,
typeFactory,
w => w.AppendRaw(childElementVariable),
ref itemVariableName,
true);
writer.Line($"{destination}.Add({itemVariableName});");
}
break;
}
case XmlDictionarySerialization dictionarySerialization:
{
writer.Append($"{destination} = new {typeFactory.CreateConcreteType(dictionarySerialization.Type)}();");
string elementsVariable = writer.GetTemporaryVariable("elements");
string elementVariable = writer.GetTemporaryVariable("e");
writer.Line($"var {elementsVariable:D} = {element}.Elements();");
using (writer.Scope($"foreach (var {elementVariable:D} in {elementsVariable})"))
{
var itemVariableName = "value";
writer.ToDeserializeCall(
dictionarySerialization.ValueSerialization,
typeFactory,
w => w.AppendRaw(elementVariable),
ref itemVariableName,
true);
writer.Line($"{destination}.Add({elementVariable}.Name.LocalName, {itemVariableName});");
}
break;
}
case XmlObjectSerialization elementSerialization:
writer.Append($"{destination} = new {typeFactory.CreateConcreteType(elementSerialization.Type)}();");
foreach (XmlObjectAttributeSerialization attribute in elementSerialization.Attributes)
{
string elementVariable = writer.GetTemporaryVariable(attribute.MemberName.ToVariableName());
writer.Line($"var {elementVariable:D} = {element}.Attribute({attribute.Name:L});");
using (writer.Scope($"if ({elementVariable} != null)"))
{
writer.Append($"{destination}.{attribute.MemberName} = ");
writer.ToDeserializeValueCall(attribute.ValueSerialization, typeFactory, w => w.AppendRaw(elementVariable));
writer.Line($";");
}
}
foreach (XmlObjectElementSerialization elem in elementSerialization.Elements)
{
var itemVariableName = "value";
writer.ToDeserializeCall(
elem.ValueSerialization,
typeFactory,
element,
ref itemVariableName);
writer.Line($"{destination}.{elem.MemberName} = {itemVariableName};");
}
foreach (var embeddedArray in elementSerialization.EmbeddedArrays)
{
CodeWriterDelegate arrayDestination = w => w.Append($"{destination}.{embeddedArray.MemberName}");
writer.ToDeserializeCall(
embeddedArray.ArraySerialization,
typeFactory,
arrayDestination,
element);
}
break;
case XmlElementValueSerialization valueSerialization:
{
writer.Append($"{destination} = ");
writer.ToDeserializeValueCall(valueSerialization.Value, typeFactory, w => w.Append(element));
writer.Line($";");
break;
}
}
}
private static void ToDeserializeValueCall(this CodeWriter writer, XmlValueSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate element)
{
switch (serialization.Type)
{
case SchemaTypeReference schemaTypeReference:
CSharpType cSharpType = typeFactory.CreateType(schemaTypeReference).WithNullable(false);
switch (typeFactory.ResolveReference(schemaTypeReference))
{
case ClientObject _:
writer.Append($"{cSharpType}.Deserialize{cSharpType.Name}({element})");
break;
case ClientEnum clientEnum when clientEnum.IsStringBased:
writer.Append($"new {cSharpType}({element}.Value)");
break;
case ClientEnum clientEnum when !clientEnum.IsStringBased:
writer.Append($"{element}.Value.To{cSharpType.Name}()");
break;
}
break;
case FrameworkTypeReference frameworkTypeReference:
var frameworkType = frameworkTypeReference.Type;
if (frameworkType == typeof(bool) ||
frameworkType == typeof(char) ||
frameworkType == typeof(short) ||
frameworkType == typeof(int) ||
frameworkType == typeof(long) ||
frameworkType == typeof(float) ||
frameworkType == typeof(double) ||
frameworkType == typeof(decimal) ||
frameworkType == typeof(string)
)
{
var type = typeFactory.CreateType(frameworkTypeReference);
writer.Append($"({type}){element}");
return;
}
writer.Append($"{element}.");
if (frameworkType == typeof(byte[]))
{
writer.AppendRaw("GetBytesFromBase64");
}
if (frameworkType == typeof(DateTimeOffset))
{
writer.AppendRaw("GetDateTimeOffsetValue");
}
if (frameworkType == typeof(TimeSpan))
{
writer.AppendRaw("GetTimeSpanValue");
}
writer.Append($"({serialization.Format.ToFormatSpecifier():L})");
break;
default:
throw new NotImplementedException(serialization.Type.ToString());
}
}
}
}

Просмотреть файл

@ -23,6 +23,12 @@ namespace AutoRest.CSharp.V3.Pipeline.Generated
}
}
internal partial class Schema
{
public string? XmlName => Serialization?.Xml?.Name;
public string Name => Language.Default.Name;
}
internal partial class Relations
{
public Relations()

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
@ -25,7 +26,8 @@ namespace AutoRest.CSharp.V3.Plugins
.Concat(codeModel.Schemas.SealedChoices ?? Enumerable.Empty<SealedChoiceSchema>())
.Concat(codeModel.Schemas.Objects ?? Enumerable.Empty<ObjectSchema>());
var models = schemas.Select(ModelBuilder.BuildModel).ToArray();
var modelBuilder = new ModelBuilder(GetMediaTypes(codeModel));
var models = schemas.Select(modelBuilder.BuildModel).ToArray();
var clients = codeModel.OperationGroups.Select(ClientBuilder.BuildClient).ToArray();
var typeProviders = models.OfType<ISchemaTypeProvider>().ToArray();
@ -115,5 +117,33 @@ namespace AutoRest.CSharp.V3.Plugins
return true;
}
// TODO: remove if https://github.com/Azure/autorest.modelerfour/issues/103 is implemented
private KnownMediaType[] GetMediaTypes(CodeModel codeModel)
{
HashSet<KnownMediaType> types = new HashSet<KnownMediaType>();
foreach (OperationGroup operationGroup in codeModel.OperationGroups)
{
foreach (Operation operation in operationGroup.Operations)
{
if (operation.Request.Protocol.Http is HttpWithBodyRequest bodyRequest)
{
types.Add(bodyRequest.KnownMediaType);
}
foreach (var response in operation.Responses!)
{
if (response is SchemaResponse _ &&
response.Protocol.Http is HttpResponse httpResponse)
{
types.Add(httpResponse.KnownMediaType);
}
}
}
}
// Order so JSON always goes first
return types.OrderBy(t => t).ToArray();
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Xml;
namespace Azure.Core
{
internal interface IXmlSerializable
{
void Write(XmlWriter writer, string? nameHint);
}
}

Просмотреть файл

@ -14,10 +14,12 @@ namespace Azure.Core
public static string ToString(bool value) => value ? "true" : "false";
public static string ToString(DateTimeOffset value, string format) => format switch
// TODO: remove useRealIso when https://github.com/Azure/autorest.testserver/pull/111 is in
public static string ToString(DateTimeOffset value, string format, bool workaroundFullIsoFormat = false) => format switch
{
"D" => value.ToString("yyyy-MM-dd"),
"S" => value.ToString("yyyy-MM-ddTHH:mm:ssZ"),
"S" when workaroundFullIsoFormat => value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
"S" when !workaroundFullIsoFormat => value.ToString("yyyy-MM-ddTHH:mm:ssZ"),
"R" => value.ToString("R"),
"U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture),
_ => throw new ArgumentException("Format is not supported", nameof(format))

Просмотреть файл

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Xml;
using System.Xml.Linq;
namespace Azure.Core
{
internal static class XElementExtensions
{
public static byte[] GetBytesFromBase64Value(this XElement element, string format) => format switch
{
"U" => TypeFormatters.FromBase64UrlString(element.Value),
_ => throw new ArgumentException("Format is not supported", nameof(format))
};
public static DateTimeOffset GetDateTimeOffsetValue(this XElement element, string format) => format switch
{
"D" => (DateTimeOffset)element,
"S" => DateTimeOffset.Parse(element.Value),
"R" => DateTimeOffset.Parse(element.Value),
"U" => DateTimeOffset.FromUnixTimeSeconds((long)element),
_ => throw new ArgumentException("Format is not supported", nameof(format))
};
public static TimeSpan GetTimeSpanValue(this XElement element, string format) => format switch
{
"P" => XmlConvert.ToTimeSpan(element.Value),
_ => throw new ArgumentException("Format is not supported", nameof(format))
};
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace Azure.Core
{
internal class XmlWriterContent : RequestContent
{
private readonly MemoryStream _stream;
public XmlWriterContent()
{
_stream = new MemoryStream();
XmlWriter = new XmlTextWriter(_stream, Encoding.UTF8);
}
public XmlWriter XmlWriter { get; }
public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
{
XmlWriter.Flush();
_stream.Position = 0;
using var content = Create(_stream);
await content.WriteToAsync(stream, cancellation);
}
public override void WriteTo(Stream stream, CancellationToken cancellation)
{
XmlWriter.Flush();
_stream.Position = 0;
using var content = Create(_stream);
content.WriteTo(stream, cancellation);
}
public override bool TryComputeLength(out long length)
{
XmlWriter.Flush();
length = _stream.Length;
return true;
}
public override void Dispose()
{
}
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Xml;
namespace Azure.Core
{
internal static class XmlWriterExtensions
{
public static void WriteObjectValue(this XmlWriter writer, object value, string? nameHint)
{
switch (value)
{
case IXmlSerializable serializable:
serializable.Write(writer, nameHint);
return;
default:
throw new NotImplementedException();
}
}
public static void WriteValue(this XmlWriter writer, DateTimeOffset value, string format) =>
writer.WriteValue(TypeFormatters.ToString(value, format, workaroundFullIsoFormat: true));
public static void WriteValue(this XmlWriter writer, TimeSpan value, string format) =>
writer.WriteValue(TypeFormatters.ToString(value, format));
public static void WriteValue(this XmlWriter writer, byte[] value, string format)
{
switch (format)
{
case "U":
writer.WriteValue(TypeFormatters.ToBase64UrlString(value));
break;
default:
throw new ArgumentException("Format is not supported", nameof(format));
}
}
}
}

Просмотреть файл

@ -60,16 +60,16 @@ namespace AutoRest.TestServer.Tests.Infrastructure
public virtual IEnumerable<string> AdditionalKnownScenarios { get; } = Array.Empty<string>();
public Task TestStatus(Func<string, HttpPipeline, Task<Response>> test)
public Task TestStatus(Func<string, HttpPipeline, Task<Response>> test, bool ignoreScenario = false)
{
return TestStatus(GetScenarioName(), test);
return TestStatus(GetScenarioName(), test, ignoreScenario);
}
private Task TestStatus(string scenario, Func<string, HttpPipeline, Task<Response>> test) => Test(scenario, async (host, pipeline) =>
private Task TestStatus(string scenario, Func<string, HttpPipeline, Task<Response>> test, bool ignoreScenario = false) => Test(scenario, async (host, pipeline) =>
{
var response = await test(host, pipeline);
Assert.AreEqual(200, response.Status, "Unexpected response " + response.ReasonPhrase);
});
Assert.That(response.Status, Is.EqualTo(200).Or.EqualTo(201), "Unexpected response " + response.ReasonPhrase);
}, ignoreScenario);
public Task Test(Action<string, HttpPipeline> test, bool ignoreScenario = false)
{

Просмотреть файл

@ -45,6 +45,8 @@ namespace AutoRest.TestServer.Tests.Infrastructure
{
BaseAddress = new Uri(Host)
};
_ = Task.Run(() => ReadOutput(_process.StandardError));
_ = Task.Run(() => ReadOutput(_process.StandardOutput));
return;
}
}
@ -114,6 +116,14 @@ namespace AutoRest.TestServer.Tests.Infrastructure
return results.ToArray();
}
private void ReadOutput(StreamReader stream)
{
while (!_process.HasExited && !stream.EndOfStream)
{
stream.ReadToEnd();
}
}
public void Stop()
{
_process.Kill(true);

Просмотреть файл

@ -0,0 +1,560 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
using NUnit.Framework;
using xml_service;
using xml_service.Models.V100;
namespace AutoRest.TestServer.Tests
{
public class XmlTests : TestServerTestBase
{
public XmlTests(TestServerVersion version) : base(version, "xml") { }
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task JsonInputInXMLSwagger() => TestStatus(async (host, pipeline) =>
{
return await new XmlOperations(ClientDiagnostics, pipeline, host).JsonInputAsync(new JSONInput()
{
Id = 42
});
});
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task JsonOutputInXMLSwagger() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).JsonOutputAsync();
Assert.AreEqual(42, result.Value.Id);
});
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutSimpleAsync() => TestStatus(async (host, pipeline) =>
{
var slideshow = new Slideshow();
slideshow.Author = "Yours Truly";
slideshow.Date = "Date of publication";
slideshow.Title = "Sample Slide Show";
slideshow.Slides = new List<Slide>()
{
new Slide()
{
Title = "Wake up to WonderWidgets!",
Type = "all"
},
new Slide()
{
Title = "Overview",
Type = "all",
Items = new[]
{
"Why WonderWidgets are great",
"",
"Who buys WonderWidgets"
}
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutSimpleAsync(slideshow);
}, true);
[Test]
public Task GetSimpleAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetSimpleAsync();
var value = result.Value;
Assert.AreEqual("Yours Truly", value.Author);
Assert.AreEqual("Date of publication", value.Date);
Assert.AreEqual("Sample Slide Show", value.Title);
var slides = value.Slides.ToArray();
Assert.AreEqual(2, slides.Length);
Assert.AreEqual("Wake up to WonderWidgets!", slides[0].Title);
Assert.AreEqual("all", slides[0].Type);
Assert.AreEqual(0, slides[0].Items.Count);
Assert.AreEqual("Overview", slides[1].Title);
Assert.AreEqual("all", slides[1].Type);
var items = slides[1].Items.ToArray();
Assert.AreEqual("Why WonderWidgets are great", items[0]);
Assert.AreEqual("", items[1]);
Assert.AreEqual("Who buys WonderWidgets", items[2]);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutComplexTypeRefNoMetaAsync() => TestStatus(async (host, pipeline) =>
{
var root = new RootWithRefAndNoMeta
{
Something = "else",
RefToModel = new ComplexTypeNoMeta()
{
ID = "myid"
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutComplexTypeRefNoMetaAsync(root);
}, true);
[Test]
public Task GetComplexTypeRefNoMetaAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetComplexTypeRefNoMetaAsync();
var value = result.Value;
Assert.AreEqual("else", value.Something);
Assert.AreEqual("myid", value.RefToModel.ID);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutComplexTypeRefWithMetaAsync() => TestStatus(async (host, pipeline) =>
{
var root = new RootWithRefAndMeta()
{
Something = "else",
RefToModel = new ComplexTypeWithMeta()
{
ID = "myid"
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutComplexTypeRefWithMetaAsync(root);
}, true);
[Test]
public Task GetComplexTypeRefWithMetaAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetComplexTypeRefWithMetaAsync();
var value = result.Value;
Assert.AreEqual("else", value.Something);
Assert.AreEqual("myid", value.RefToModel.ID);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutRootListSingleItemAsync() => TestStatus(async (host, pipeline) =>
{
var root = new[]
{
new Banana()
{
Name = "Cavendish",
Flavor = "Sweet",
Expiration = DateTimeOffset.Parse("2018-02-28T00:40:00.123Z")
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutRootListSingleItemAsync(root);
}, true);
[Test]
public Task GetRootListSingleItemAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetRootListSingleItemAsync();
var value = result.Value;
var item = value.Single();
Assert.AreEqual("Cavendish", item.Name);
Assert.AreEqual("Sweet", item.Flavor);
Assert.AreEqual(DateTimeOffset.Parse("2018-02-28T00:40:00.123Z"), item.Expiration);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutEmptyListAsync() => TestStatus(async (host, pipeline) =>
{
var root = new Slideshow
{
Slides = new List<Slide>()
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutEmptyListAsync(root);
}, true);
[Test]
public Task GetEmptyListAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetEmptyListAsync();
var value = result.Value;
Assert.AreEqual(0, value.Slides.Count);
Assert.Null(value.Date);
Assert.Null(value.Author);
Assert.Null(value.Title);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutEmptyChildElementAsync() => TestStatus(async (host, pipeline) =>
{
var root = new Banana()
{
Name = "Unknown Banana",
Flavor = "",
Expiration = DateTimeOffset.Parse("2012-02-24T00:53:52.789Z")
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutEmptyChildElementAsync(root);
}, true);
[Test]
public Task GetEmptyChildElementAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetEmptyChildElementAsync();
var value = result.Value;
Assert.AreEqual("Unknown Banana", value.Name);
Assert.AreEqual("", value.Flavor);
Assert.AreEqual(DateTimeOffset.Parse("2012-02-24T00:53:52.789Z"), value.Expiration);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutWrappedListsAsync() => TestStatus(async (host, pipeline) =>
{
var root = new AppleBarrel()
{
BadApples = new[] {"Red Delicious"},
GoodApples = new[] {"Fuji", "Gala"}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutWrappedListsAsync(root);
}, true);
[Test]
public Task GetWrappedListsAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetWrappedListsAsync();
var value = result.Value;
CollectionAssert.AreEqual(new[] {"Red Delicious"}, value.BadApples);
CollectionAssert.AreEqual(new[] {"Fuji", "Gala"}, value.GoodApples);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutEmptyWrappedListsAsync() => TestStatus(async (host, pipeline) =>
{
var root = new AppleBarrel()
{
BadApples = new string[] {},
GoodApples = new string[] {}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutEmptyWrappedListsAsync(root);
}, true);
[Test]
public Task GetEmptyWrappedListsAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetEmptyWrappedListsAsync();
var value = result.Value;
CollectionAssert.AreEqual(new string[] {}, value.BadApples);
CollectionAssert.AreEqual(new string[] {}, value.GoodApples);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutAclsAsync() => TestStatus(async (host, pipeline) =>
{
var root = new List<SignedIdentifier>()
{
new SignedIdentifier()
{
Id = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=",
AccessPolicy =
{
Start = DateTimeOffset.Parse("2009-09-28T08:49:37.123Z"),
Expiry = DateTimeOffset.Parse("2009-09-29T08:49:37.123Z"),
Permission = "rwd"
}
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutAclsAsync(root);
}, true);
[Test]
public Task GetAclsAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetAclsAsync();
var value = result.Value;
Assert.AreEqual(1, value.Count);
var acl = value.Single();
Assert.AreEqual("MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=", acl.Id);
Assert.AreEqual(DateTimeOffset.Parse("2009-09-28T08:49:37.123Z"), acl.AccessPolicy.Start);
Assert.AreEqual("rwd", acl.AccessPolicy.Permission);
Assert.AreEqual(DateTimeOffset.Parse("2009-09-29T08:49:37.123Z"), acl.AccessPolicy.Expiry);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutRootListAsync() => TestStatus(async (host, pipeline) =>
{
var root = new List<Banana>()
{
new Banana()
{
Name = "Cavendish",
Flavor = "Sweet",
Expiration = DateTimeOffset.Parse("2018-02-28T00:40:00.123Z")
},
new Banana()
{
Name = "Plantain",
Flavor = "Savory",
Expiration = DateTimeOffset.Parse("2018-02-28T00:40:00.123Z")
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutRootListAsync(root);
}, true);
[Test]
public Task GetRootListAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetRootListAsync();
var values = result.Value.ToArray();
Assert.AreEqual(2, values.Length);
Assert.AreEqual("Cavendish", values[0].Name);
Assert.AreEqual("Sweet", values[0].Flavor);
Assert.AreEqual(DateTimeOffset.Parse("2018-02-28T00:40:00.123Z"), values[0].Expiration);
Assert.AreEqual("Plantain", values[1].Name);
Assert.AreEqual("Savory", values[1].Flavor);
Assert.AreEqual(DateTimeOffset.Parse("2018-02-28T00:40:00.123Z"), values[1].Expiration);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutEmptyRootListAsync() => TestStatus(async (host, pipeline) =>
{
var root = new List<Banana>();
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutEmptyRootListAsync(root);
}, true);
[Test]
public Task GetEmptyRootListAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetEmptyRootListAsync();
var values = result.Value.ToArray();
Assert.AreEqual(0, values.Length);
}, true);
[Test]
public Task ListContainersAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).ListContainersAsync();
var value = result.Value;
Assert.AreEqual("video", value.NextMarker);
Assert.AreEqual("https://myaccount.blob.core.windows.net/", value.ServiceEndpoint);
Assert.AreEqual(3, value.MaxResults);
var containers = value.Containers.ToArray();
Assert.AreEqual("audio", containers[0].Name);
Assert.AreEqual("0x8CACB9BD7C6B1B2", containers[0].Properties.Etag);
Assert.AreEqual(PublicAccessType.Container, containers[0].Properties.PublicAccess);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 26 Oct 2016 20:39:39 GMT"), containers[0].Properties.LastModified);
Assert.AreEqual("images", containers[1].Name);
Assert.AreEqual("0x8CACB9BD7C1EEEC", containers[1].Properties.Etag);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 26 Oct 2016 20:39:39 GMT"), containers[1].Properties.LastModified);
Assert.AreEqual("textfiles", containers[2].Name);
Assert.AreEqual("0x8CACB9BD7BACAC3", containers[2].Properties.Etag);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 26 Oct 2016 20:39:39 GMT"), containers[2].Properties.LastModified);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task GetHeadersAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetHeadersAsync();
var value = result.Headers;
Assert.AreEqual("custom-value", value.CustomHeader);
}, true);
[Test]
public Task ListBlobsAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).ListBlobsAsync();
var value = result.Value;
Assert.AreEqual("https://myaccount.blob.core.windows.net/mycontainer", value.ContainerName);
var blobs = value.Blobs.Blob.ToArray();
Assert.AreEqual(5, blobs.Length);
Assert.AreEqual("blob1.txt", blobs[0].Name);
Assert.AreEqual(false, blobs[0].Deleted);
Assert.AreEqual("0x8CBFF45D8A29A19", blobs[0].Properties.Etag);
Assert.AreEqual("en-US", blobs[0].Properties.ContentLanguage);
Assert.AreEqual(LeaseStatusType.Unlocked, blobs[0].Properties.LeaseStatus);
Assert.AreEqual(BlobType.BlockBlob, blobs[0].Properties.BlobType);
Assert.AreEqual("no-cache", blobs[0].Properties.CacheControl);
Assert.AreEqual("text/html", blobs[0].Properties.ContentType);
Assert.AreEqual(100, blobs[0].Properties.ContentLength);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 09 Sep 2009 09:20:02 GMT"), blobs[0].Properties.LastModified);
Assert.AreEqual("blob2.txt", blobs[1].Name);
Assert.AreEqual("2009-09-09T09:20:03.0427659Z", blobs[1].Snapshot);
Assert.AreEqual(false, blobs[1].Deleted);
Assert.AreEqual("0x8CBFF45D8B4C212", blobs[1].Properties.Etag);
Assert.AreEqual("gzip", blobs[1].Properties.ContentEncoding);
Assert.AreEqual(BlobType.BlockBlob, blobs[1].Properties.BlobType);
Assert.AreEqual("application/octet-stream", blobs[1].Properties.ContentType);
Assert.AreEqual(5000, blobs[1].Properties.ContentLength);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 09 Sep 2009 09:20:02 GMT"), blobs[1].Properties.LastModified);
Assert.AreEqual("green", blobs[1].Metadata["Color"]);
Assert.AreEqual("02", blobs[1].Metadata["BlobNumber"]);
Assert.AreEqual("SomeMetadataValue", blobs[1].Metadata["SomeMetadataName"]);
Assert.AreEqual("nasdf$@#$$", blobs[1].Metadata["x-ms-invalid-name"]);
Assert.AreEqual("blob2.txt", blobs[2].Name);
Assert.AreEqual("2009-09-09T09:20:03.1587543Z", blobs[2].Snapshot);
Assert.AreEqual(false, blobs[2].Deleted);
Assert.AreEqual("0x8CBFF45D8B4C212", blobs[2].Properties.Etag);
Assert.AreEqual("gzip", blobs[2].Properties.ContentEncoding);
Assert.AreEqual(BlobType.BlockBlob, blobs[2].Properties.BlobType);
Assert.AreEqual("application/octet-stream", blobs[2].Properties.ContentType);
Assert.AreEqual(5000, blobs[2].Properties.ContentLength);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 09 Sep 2009 09:20:02 GMT"), blobs[2].Properties.LastModified);
Assert.AreEqual("green", blobs[2].Metadata["Color"]);
Assert.AreEqual("02", blobs[2].Metadata["BlobNumber"]);
Assert.AreEqual("SomeMetadataValue", blobs[2].Metadata["SomeMetadataName"]);
Assert.AreEqual("blob2.txt", blobs[3].Name);
Assert.AreEqual(false, blobs[3].Deleted);
Assert.AreEqual("0x8CBFF45D8B4C212", blobs[3].Properties.Etag);
Assert.AreEqual("gzip", blobs[3].Properties.ContentEncoding);
Assert.AreEqual(BlobType.BlockBlob, blobs[3].Properties.BlobType);
Assert.AreEqual("application/octet-stream", blobs[3].Properties.ContentType);
Assert.AreEqual(5000, blobs[3].Properties.ContentLength);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 09 Sep 2009 09:20:02 GMT"), blobs[3].Properties.LastModified);
Assert.AreEqual("green", blobs[3].Metadata["Color"]);
Assert.AreEqual("02", blobs[3].Metadata["BlobNumber"]);
Assert.AreEqual("SomeMetadataValue", blobs[3].Metadata["SomeMetadataName"]);
Assert.AreEqual("blob3.txt", blobs[4].Name);
Assert.AreEqual(false, blobs[4].Deleted);
Assert.AreEqual("0x8CBFF45D911FADF", blobs[4].Properties.Etag);
Assert.AreEqual(BlobType.PageBlob, blobs[4].Properties.BlobType);
Assert.AreEqual("image/jpeg", blobs[4].Properties.ContentType);
Assert.AreEqual(16384, blobs[4].Properties.ContentLength);
Assert.AreEqual(LeaseStatusType.Locked, blobs[4].Properties.LeaseStatus);
Assert.AreEqual(3, blobs[4].Properties.BlobSequenceNumber);
Assert.AreEqual(DateTimeOffset.Parse("Wed, 09 Sep 2009 09:20:03 GMT"), blobs[4].Properties.LastModified);
Assert.AreEqual("yellow", blobs[4].Metadata["Color"]);
Assert.AreEqual("03", blobs[4].Metadata["BlobNumber"]);
Assert.AreEqual("SomeMetadataValue", blobs[4].Metadata["SomeMetadataName"]);
}, true);
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No match")]
public Task PutServicePropertiesAsync() => TestStatus(async (host, pipeline) =>
{
var properties = new StorageServiceProperties()
{
Logging = new Logging()
{
Version = "1.0",
Delete = true,
Read = false,
Write = true,
RetentionPolicy = new RetentionPolicy()
{
Days = 7,
Enabled = true
}
},
HourMetrics = new Metrics()
{
Version = "1.0",
Enabled = true,
IncludeAPIs = false,
RetentionPolicy = new RetentionPolicy()
{
Days = 7,
Enabled = true
}
},
MinuteMetrics = new Metrics()
{
Version = "1.0",
Enabled = true,
IncludeAPIs = true,
RetentionPolicy = new RetentionPolicy()
{
Days = 7,
Enabled = true
}
}
};
return await new XmlOperations(ClientDiagnostics, pipeline, host).PutServicePropertiesAsync(properties);
}, true);
[Test]
public Task GetServicePropertiesAsync() => Test(async (host, pipeline) =>
{
var result = await new XmlOperations(ClientDiagnostics, pipeline, host).GetServicePropertiesAsync();
var value = result.Value;
Assert.AreEqual("1.0", value.Logging.Version);
Assert.AreEqual(true, value.Logging.Delete);
Assert.AreEqual(false, value.Logging.Read);
Assert.AreEqual(true, value.Logging.Write);
Assert.AreEqual(7, value.Logging.RetentionPolicy.Days);
Assert.AreEqual(true, value.Logging.RetentionPolicy.Enabled);
Assert.AreEqual("1.0", value.HourMetrics.Version);
Assert.AreEqual(true, value.HourMetrics.Enabled);
Assert.AreEqual(false, value.HourMetrics.IncludeAPIs);
Assert.AreEqual(7, value.HourMetrics.RetentionPolicy.Days);
Assert.AreEqual(true, value.HourMetrics.RetentionPolicy.Enabled);
Assert.AreEqual("1.0", value.MinuteMetrics.Version);
Assert.AreEqual(true, value.MinuteMetrics.Enabled);
Assert.AreEqual(true, value.MinuteMetrics.IncludeAPIs);
Assert.AreEqual(7, value.MinuteMetrics.RetentionPolicy.Days);
Assert.AreEqual(true, value.MinuteMetrics.RetentionPolicy.Enabled);
}, true);
}
}

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using Azure.Core;
namespace body_file.Models.V100
{
public partial class Error : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Status != null)
{
writer.WritePropertyName("status");
writer.WriteNumberValue(Status.Value);
}
if (Message != null)
{
writer.WritePropertyName("message");
writer.WriteStringValue(Message);
}
writer.WriteEndObject();
}
internal static Error DeserializeError(JsonElement element)
{
Error result = new Error();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("status"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Status = property.Value.GetInt32();
continue;
}
if (property.NameEquals("message"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Message = property.Value.GetString();
continue;
}
}
return result;
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using Azure.Core;
namespace custom_baseUrl.Models.V100
{
public partial class Error : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Status != null)
{
writer.WritePropertyName("status");
writer.WriteNumberValue(Status.Value);
}
if (Message != null)
{
writer.WritePropertyName("message");
writer.WriteStringValue(Message);
}
writer.WriteEndObject();
}
internal static Error DeserializeError(JsonElement element)
{
Error result = new Error();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("status"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Status = property.Value.GetInt32();
continue;
}
if (property.NameEquals("message"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Message = property.Value.GetString();
continue;
}
}
return result;
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using Azure.Core;
namespace header.Models.V100
{
public partial class Error : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Status != null)
{
writer.WritePropertyName("status");
writer.WriteNumberValue(Status.Value);
}
if (Message != null)
{
writer.WritePropertyName("message");
writer.WriteStringValue(Message);
}
writer.WriteEndObject();
}
internal static Error DeserializeError(JsonElement element)
{
Error result = new Error();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("status"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Status = property.Value.GetInt32();
continue;
}
if (property.NameEquals("message"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Message = property.Value.GetString();
continue;
}
}
return result;
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using Azure.Core;
namespace url_multi_collectionFormat.Models.V100
{
public partial class Error : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Status != null)
{
writer.WritePropertyName("status");
writer.WriteNumberValue(Status.Value);
}
if (Message != null)
{
writer.WritePropertyName("message");
writer.WriteStringValue(Message);
}
writer.WriteEndObject();
}
internal static Error DeserializeError(JsonElement element)
{
Error result = new Error();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("status"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Status = property.Value.GetInt32();
continue;
}
if (property.NameEquals("message"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Message = property.Value.GetString();
continue;
}
}
return result;
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using Azure.Core;
namespace url.Models.V100
{
public partial class Error : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Status != null)
{
writer.WritePropertyName("status");
writer.WriteNumberValue(Status.Value);
}
if (Message != null)
{
writer.WritePropertyName("message");
writer.WriteStringValue(Message);
}
writer.WriteEndObject();
}
internal static Error DeserializeError(JsonElement element)
{
Error result = new Error();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("status"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Status = property.Value.GetInt32();
continue;
}
if (property.NameEquals("message"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Message = property.Value.GetString();
continue;
}
}
return result;
}
}
}

Просмотреть файл

@ -40,11 +40,8 @@ namespace validation.Models.V100
writer.WriteNumberValue(ConstInt);
writer.WritePropertyName("constString");
writer.WriteStringValue(ConstString);
if (ConstStringAsEnum != null)
{
writer.WritePropertyName("constStringAsEnum");
writer.WriteStringValue(ConstStringAsEnum);
}
writer.WritePropertyName("constStringAsEnum");
writer.WriteStringValue(ConstStringAsEnum);
writer.WriteEndObject();
}
internal static Product DeserializeProduct(JsonElement element)
@ -105,10 +102,6 @@ namespace validation.Models.V100
}
if (property.NameEquals("constStringAsEnum"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ConstStringAsEnum = property.Value.GetString();
continue;
}

Просмотреть файл

@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class AccessPolicy : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Start");
writer.WriteStringValue(Start, "S");
writer.WritePropertyName("Expiry");
writer.WriteStringValue(Expiry, "S");
writer.WritePropertyName("Permission");
writer.WriteStringValue(Permission);
writer.WriteEndObject();
}
internal static AccessPolicy DeserializeAccessPolicy(JsonElement element)
{
AccessPolicy result = new AccessPolicy();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Start"))
{
result.Start = property.Value.GetDateTimeOffset("S");
continue;
}
if (property.NameEquals("Expiry"))
{
result.Expiry = property.Value.GetDateTimeOffset("S");
continue;
}
if (property.NameEquals("Permission"))
{
result.Permission = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "AccessPolicy");
writer.WriteStartElement("Start");
writer.WriteValue(Start, "S");
writer.WriteEndElement();
writer.WriteStartElement("Expiry");
writer.WriteValue(Expiry, "S");
writer.WriteEndElement();
writer.WriteStartElement("Permission");
writer.WriteValue(Permission);
writer.WriteEndElement();
writer.WriteEndElement();
}
internal static AccessPolicy DeserializeAccessPolicy(XElement element)
{
AccessPolicy result = default;
result = new AccessPolicy(); DateTimeOffset value = default;
var start = element.Element("Start");
if (start != null)
{
value = start.GetDateTimeOffsetValue("S");
}
result.Start = value;
DateTimeOffset value0 = default;
var expiry = element.Element("Expiry");
if (expiry != null)
{
value0 = expiry.GetDateTimeOffsetValue("S");
}
result.Expiry = value0;
string value1 = default;
var permission = element.Element("Permission");
if (permission != null)
{
value1 = (string)permission;
}
result.Permission = value1;
return result;
}
}
}

14
test/TestServerProjects/xml-service/Generated/Models/AccessPolicy.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
public partial class AccessPolicy
{
public DateTimeOffset Start { get; set; }
public DateTimeOffset Expiry { get; set; }
public string Permission { get; set; }
}
}

51
test/TestServerProjects/xml-service/Generated/Models/AccessTier.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace xml_service.Models.V100
{
public readonly partial struct AccessTier : IEquatable<AccessTier>
{
private readonly string? _value;
public AccessTier(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string P4Value = "P4";
private const string P6Value = "P6";
private const string P10Value = "P10";
private const string P20Value = "P20";
private const string P30Value = "P30";
private const string P40Value = "P40";
private const string P50Value = "P50";
private const string HotValue = "Hot";
private const string CoolValue = "Cool";
private const string ArchiveValue = "Archive";
public static AccessTier P4 { get; } = new AccessTier(P4Value);
public static AccessTier P6 { get; } = new AccessTier(P6Value);
public static AccessTier P10 { get; } = new AccessTier(P10Value);
public static AccessTier P20 { get; } = new AccessTier(P20Value);
public static AccessTier P30 { get; } = new AccessTier(P30Value);
public static AccessTier P40 { get; } = new AccessTier(P40Value);
public static AccessTier P50 { get; } = new AccessTier(P50Value);
public static AccessTier Hot { get; } = new AccessTier(HotValue);
public static AccessTier Cool { get; } = new AccessTier(CoolValue);
public static AccessTier Archive { get; } = new AccessTier(ArchiveValue);
public static bool operator ==(AccessTier left, AccessTier right) => left.Equals(right);
public static bool operator !=(AccessTier left, AccessTier right) => !left.Equals(right);
public static implicit operator AccessTier(string value) => new AccessTier(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is AccessTier other && Equals(other);
public bool Equals(AccessTier other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
}
}

Просмотреть файл

@ -0,0 +1,128 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class AppleBarrel : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (GoodApples != null)
{
writer.WritePropertyName("GoodApples");
writer.WriteStartArray();
foreach (var item in GoodApples)
{
writer.WriteStringValue(item);
}
writer.WriteEndArray();
}
if (BadApples != null)
{
writer.WritePropertyName("BadApples");
writer.WriteStartArray();
foreach (var item in BadApples)
{
writer.WriteStringValue(item);
}
writer.WriteEndArray();
}
writer.WriteEndObject();
}
internal static AppleBarrel DeserializeAppleBarrel(JsonElement element)
{
AppleBarrel result = new AppleBarrel();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("GoodApples"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.GoodApples = new List<string>();
foreach (var item in property.Value.EnumerateArray())
{
result.GoodApples.Add(item.GetString());
}
continue;
}
if (property.NameEquals("BadApples"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.BadApples = new List<string>();
foreach (var item in property.Value.EnumerateArray())
{
result.BadApples.Add(item.GetString());
}
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "AppleBarrel");
if (GoodApples != null)
{
writer.WriteStartElement("GoodApples");
foreach (var item in GoodApples)
{
writer.WriteStartElement("Apple");
writer.WriteValue(item);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
if (BadApples != null)
{
writer.WriteStartElement("BadApples");
foreach (var item in BadApples)
{
writer.WriteStartElement("Apple");
writer.WriteValue(item);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static AppleBarrel DeserializeAppleBarrel(XElement element)
{
AppleBarrel result = default;
result = new AppleBarrel(); var goodApples = element.Element("GoodApples");
if (goodApples != null)
{
result.GoodApples = new List<string>();
foreach (var e in goodApples.Elements("Apple"))
{
string value = default;
value = (string)e;
result.GoodApples.Add(value);
}
}
var badApples = element.Element("BadApples");
if (badApples != null)
{
result.BadApples = new List<string>();
foreach (var e in badApples.Elements("Apple"))
{
string value = default;
value = (string)e;
result.BadApples.Add(value);
}
}
return result;
}
}
}

13
test/TestServerProjects/xml-service/Generated/Models/AppleBarrel.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace xml_service.Models.V100
{
public partial class AppleBarrel
{
public ICollection<string>? GoodApples { get; set; }
public ICollection<string>? BadApples { get; set; }
}
}

35
test/TestServerProjects/xml-service/Generated/Models/ArchiveStatus.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace xml_service.Models.V100
{
public readonly partial struct ArchiveStatus : IEquatable<ArchiveStatus>
{
private readonly string? _value;
public ArchiveStatus(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string RehydratePendingToHotValue = "rehydrate-pending-to-hot";
private const string RehydratePendingToCoolValue = "rehydrate-pending-to-cool";
public static ArchiveStatus RehydratePendingToHot { get; } = new ArchiveStatus(RehydratePendingToHotValue);
public static ArchiveStatus RehydratePendingToCool { get; } = new ArchiveStatus(RehydratePendingToCoolValue);
public static bool operator ==(ArchiveStatus left, ArchiveStatus right) => left.Equals(right);
public static bool operator !=(ArchiveStatus left, ArchiveStatus right) => !left.Equals(right);
public static implicit operator ArchiveStatus(string value) => new ArchiveStatus(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is ArchiveStatus other && Equals(other);
public bool Equals(ArchiveStatus other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
}
}

Просмотреть файл

@ -0,0 +1,119 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Banana : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Name != null)
{
writer.WritePropertyName("name");
writer.WriteStringValue(Name);
}
if (Flavor != null)
{
writer.WritePropertyName("flavor");
writer.WriteStringValue(Flavor);
}
if (Expiration != null)
{
writer.WritePropertyName("expiration");
writer.WriteStringValue(Expiration.Value, "S");
}
writer.WriteEndObject();
}
internal static Banana DeserializeBanana(JsonElement element)
{
Banana result = new Banana();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("name"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Name = property.Value.GetString();
continue;
}
if (property.NameEquals("flavor"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Flavor = property.Value.GetString();
continue;
}
if (property.NameEquals("expiration"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Expiration = property.Value.GetDateTimeOffset("S");
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "banana");
if (Name != null)
{
writer.WriteStartElement("name");
writer.WriteValue(Name);
writer.WriteEndElement();
}
if (Flavor != null)
{
writer.WriteStartElement("flavor");
writer.WriteValue(Flavor);
writer.WriteEndElement();
}
if (Expiration != null)
{
writer.WriteStartElement("expiration");
writer.WriteValue(Expiration.Value, "S");
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static Banana DeserializeBanana(XElement element)
{
Banana result = default;
result = new Banana(); string? value = default;
var name = element.Element("name");
if (name != null)
{
value = (string?)name;
}
result.Name = value;
string? value0 = default;
var flavor = element.Element("flavor");
if (flavor != null)
{
value0 = (string?)flavor;
}
result.Flavor = value0;
DateTimeOffset? value1 = default;
var expiration = element.Element("expiration");
if (expiration != null)
{
value1 = expiration.GetDateTimeOffsetValue("S");
}
result.Expiration = value1;
return result;
}
}
}

14
test/TestServerProjects/xml-service/Generated/Models/Banana.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
public partial class Banana
{
public string? Name { get; set; }
public string? Flavor { get; set; }
public DateTimeOffset? Expiration { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,150 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Blob : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Name");
writer.WriteStringValue(Name);
writer.WritePropertyName("Deleted");
writer.WriteBooleanValue(Deleted);
writer.WritePropertyName("Snapshot");
writer.WriteStringValue(Snapshot);
writer.WritePropertyName("Properties");
writer.WriteObjectValue(Properties);
if (Metadata != null)
{
writer.WritePropertyName("Metadata");
writer.WriteStartObject();
foreach (var item in Metadata)
{
writer.WritePropertyName(item.Key);
writer.WriteStringValue(item.Value);
}
writer.WriteEndObject();
}
writer.WriteEndObject();
}
internal static Blob DeserializeBlob(JsonElement element)
{
Blob result = new Blob();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Name"))
{
result.Name = property.Value.GetString();
continue;
}
if (property.NameEquals("Deleted"))
{
result.Deleted = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("Snapshot"))
{
result.Snapshot = property.Value.GetString();
continue;
}
if (property.NameEquals("Properties"))
{
result.Properties = BlobProperties.DeserializeBlobProperties(property.Value);
continue;
}
if (property.NameEquals("Metadata"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Metadata = new Dictionary<string, string>();
foreach (var property0 in property.Value.EnumerateObject())
{
result.Metadata.Add(property0.Name, property0.Value.GetString());
}
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Blob");
writer.WriteStartElement("Name");
writer.WriteValue(Name);
writer.WriteEndElement();
writer.WriteStartElement("Deleted");
writer.WriteValue(Deleted);
writer.WriteEndElement();
writer.WriteStartElement("Snapshot");
writer.WriteValue(Snapshot);
writer.WriteEndElement();
writer.WriteObjectValue(Properties, "Properties");
if (Metadata != null)
{
foreach (var pair in Metadata)
{
writer.WriteStartElement("!dictionary-item");
writer.WriteValue(pair.Value);
writer.WriteEndElement();
}
}
writer.WriteEndElement();
}
internal static Blob DeserializeBlob(XElement element)
{
Blob result = default;
result = new Blob(); string value = default;
var name = element.Element("Name");
if (name != null)
{
value = (string)name;
}
result.Name = value;
bool value0 = default;
var deleted = element.Element("Deleted");
if (deleted != null)
{
value0 = (bool)deleted;
}
result.Deleted = value0;
string value1 = default;
var snapshot = element.Element("Snapshot");
if (snapshot != null)
{
value1 = (string)snapshot;
}
result.Snapshot = value1;
BlobProperties value2 = default;
var properties = element.Element("Properties");
if (properties != null)
{
value2 = BlobProperties.DeserializeBlobProperties(properties);
}
result.Properties = value2;
IDictionary<string, string>? value3 = default;
var metadata = element.Element("Metadata");
if (metadata != null)
{
value3 = new Dictionary<string, string>(); var elements = metadata.Elements();
foreach (var e in elements)
{
string value4 = default;
value4 = (string)e;
value3.Add(e.Name.LocalName, value4);
}
}
result.Metadata = value3;
return result;
}
}
}

16
test/TestServerProjects/xml-service/Generated/Models/Blob.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace xml_service.Models.V100
{
public partial class Blob
{
public string Name { get; set; }
public bool Deleted { get; set; }
public string Snapshot { get; set; }
public BlobProperties Properties { get; set; } = new BlobProperties();
public IDictionary<string, string>? Metadata { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class BlobPrefix : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Name");
writer.WriteStringValue(Name);
writer.WriteEndObject();
}
internal static BlobPrefix DeserializeBlobPrefix(JsonElement element)
{
BlobPrefix result = new BlobPrefix();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Name"))
{
result.Name = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "BlobPrefix");
writer.WriteStartElement("Name");
writer.WriteValue(Name);
writer.WriteEndElement();
writer.WriteEndElement();
}
internal static BlobPrefix DeserializeBlobPrefix(XElement element)
{
BlobPrefix result = default;
result = new BlobPrefix(); string value = default;
var name = element.Element("Name");
if (name != null)
{
value = (string)name;
}
result.Name = value;
return result;
}
}
}

10
test/TestServerProjects/xml-service/Generated/Models/BlobPrefix.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class BlobPrefix
{
public string Name { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,774 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class BlobProperties : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Last-Modified");
writer.WriteStringValue(LastModified, "R");
writer.WritePropertyName("Etag");
writer.WriteStringValue(Etag);
if (ContentLength != null)
{
writer.WritePropertyName("Content-Length");
writer.WriteNumberValue(ContentLength.Value);
}
if (ContentType != null)
{
writer.WritePropertyName("Content-Type");
writer.WriteStringValue(ContentType);
}
if (ContentEncoding != null)
{
writer.WritePropertyName("Content-Encoding");
writer.WriteStringValue(ContentEncoding);
}
if (ContentLanguage != null)
{
writer.WritePropertyName("Content-Language");
writer.WriteStringValue(ContentLanguage);
}
if (ContentMD5 != null)
{
writer.WritePropertyName("Content-MD5");
writer.WriteStringValue(ContentMD5);
}
if (ContentDisposition != null)
{
writer.WritePropertyName("Content-Disposition");
writer.WriteStringValue(ContentDisposition);
}
if (CacheControl != null)
{
writer.WritePropertyName("Cache-Control");
writer.WriteStringValue(CacheControl);
}
if (BlobSequenceNumber != null)
{
writer.WritePropertyName("x-ms-blob-sequence-number");
writer.WriteNumberValue(BlobSequenceNumber.Value);
}
if (BlobType != null)
{
writer.WritePropertyName("BlobType");
writer.WriteStringValue(BlobType.Value.ToSerialString());
}
if (LeaseStatus != null)
{
writer.WritePropertyName("LeaseStatus");
writer.WriteStringValue(LeaseStatus.Value.ToSerialString());
}
if (LeaseState != null)
{
writer.WritePropertyName("LeaseState");
writer.WriteStringValue(LeaseState.Value.ToSerialString());
}
if (LeaseDuration != null)
{
writer.WritePropertyName("LeaseDuration");
writer.WriteStringValue(LeaseDuration.Value.ToSerialString());
}
if (CopyId != null)
{
writer.WritePropertyName("CopyId");
writer.WriteStringValue(CopyId);
}
if (CopyStatus != null)
{
writer.WritePropertyName("CopyStatus");
writer.WriteStringValue(CopyStatus.Value.ToSerialString());
}
if (CopySource != null)
{
writer.WritePropertyName("CopySource");
writer.WriteStringValue(CopySource);
}
if (CopyProgress != null)
{
writer.WritePropertyName("CopyProgress");
writer.WriteStringValue(CopyProgress);
}
if (CopyCompletionTime != null)
{
writer.WritePropertyName("CopyCompletionTime");
writer.WriteStringValue(CopyCompletionTime.Value, "R");
}
if (CopyStatusDescription != null)
{
writer.WritePropertyName("CopyStatusDescription");
writer.WriteStringValue(CopyStatusDescription);
}
if (ServerEncrypted != null)
{
writer.WritePropertyName("ServerEncrypted");
writer.WriteBooleanValue(ServerEncrypted.Value);
}
if (IncrementalCopy != null)
{
writer.WritePropertyName("IncrementalCopy");
writer.WriteBooleanValue(IncrementalCopy.Value);
}
if (DestinationSnapshot != null)
{
writer.WritePropertyName("DestinationSnapshot");
writer.WriteStringValue(DestinationSnapshot);
}
if (DeletedTime != null)
{
writer.WritePropertyName("DeletedTime");
writer.WriteStringValue(DeletedTime.Value, "R");
}
if (RemainingRetentionDays != null)
{
writer.WritePropertyName("RemainingRetentionDays");
writer.WriteNumberValue(RemainingRetentionDays.Value);
}
if (AccessTier != null)
{
writer.WritePropertyName("AccessTier");
writer.WriteStringValue(AccessTier.Value.ToString());
}
if (AccessTierInferred != null)
{
writer.WritePropertyName("AccessTierInferred");
writer.WriteBooleanValue(AccessTierInferred.Value);
}
if (ArchiveStatus != null)
{
writer.WritePropertyName("ArchiveStatus");
writer.WriteStringValue(ArchiveStatus.Value.ToString());
}
writer.WriteEndObject();
}
internal static BlobProperties DeserializeBlobProperties(JsonElement element)
{
BlobProperties result = new BlobProperties();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Last-Modified"))
{
result.LastModified = property.Value.GetDateTimeOffset("R");
continue;
}
if (property.NameEquals("Etag"))
{
result.Etag = property.Value.GetString();
continue;
}
if (property.NameEquals("Content-Length"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentLength = property.Value.GetInt64();
continue;
}
if (property.NameEquals("Content-Type"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentType = property.Value.GetString();
continue;
}
if (property.NameEquals("Content-Encoding"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentEncoding = property.Value.GetString();
continue;
}
if (property.NameEquals("Content-Language"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentLanguage = property.Value.GetString();
continue;
}
if (property.NameEquals("Content-MD5"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentMD5 = property.Value.GetString();
continue;
}
if (property.NameEquals("Content-Disposition"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ContentDisposition = property.Value.GetString();
continue;
}
if (property.NameEquals("Cache-Control"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CacheControl = property.Value.GetString();
continue;
}
if (property.NameEquals("x-ms-blob-sequence-number"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.BlobSequenceNumber = property.Value.GetInt32();
continue;
}
if (property.NameEquals("BlobType"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.BlobType = property.Value.GetString().ToBlobType();
continue;
}
if (property.NameEquals("LeaseStatus"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseStatus = property.Value.GetString().ToLeaseStatusType();
continue;
}
if (property.NameEquals("LeaseState"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseState = property.Value.GetString().ToLeaseStateType();
continue;
}
if (property.NameEquals("LeaseDuration"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseDuration = property.Value.GetString().ToLeaseDurationType();
continue;
}
if (property.NameEquals("CopyId"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopyId = property.Value.GetString();
continue;
}
if (property.NameEquals("CopyStatus"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopyStatus = property.Value.GetString().ToCopyStatusType();
continue;
}
if (property.NameEquals("CopySource"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopySource = property.Value.GetString();
continue;
}
if (property.NameEquals("CopyProgress"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopyProgress = property.Value.GetString();
continue;
}
if (property.NameEquals("CopyCompletionTime"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopyCompletionTime = property.Value.GetDateTimeOffset("R");
continue;
}
if (property.NameEquals("CopyStatusDescription"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.CopyStatusDescription = property.Value.GetString();
continue;
}
if (property.NameEquals("ServerEncrypted"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ServerEncrypted = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("IncrementalCopy"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.IncrementalCopy = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("DestinationSnapshot"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.DestinationSnapshot = property.Value.GetString();
continue;
}
if (property.NameEquals("DeletedTime"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.DeletedTime = property.Value.GetDateTimeOffset("R");
continue;
}
if (property.NameEquals("RemainingRetentionDays"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.RemainingRetentionDays = property.Value.GetInt32();
continue;
}
if (property.NameEquals("AccessTier"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.AccessTier = new AccessTier(property.Value.GetString());
continue;
}
if (property.NameEquals("AccessTierInferred"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.AccessTierInferred = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("ArchiveStatus"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ArchiveStatus = new ArchiveStatus(property.Value.GetString());
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "BlobProperties");
writer.WriteStartElement("Last-Modified");
writer.WriteValue(LastModified, "R");
writer.WriteEndElement();
writer.WriteStartElement("Etag");
writer.WriteValue(Etag);
writer.WriteEndElement();
if (ContentLength != null)
{
writer.WriteStartElement("Content-Length");
writer.WriteValue(ContentLength.Value);
writer.WriteEndElement();
}
if (ContentType != null)
{
writer.WriteStartElement("Content-Type");
writer.WriteValue(ContentType);
writer.WriteEndElement();
}
if (ContentEncoding != null)
{
writer.WriteStartElement("Content-Encoding");
writer.WriteValue(ContentEncoding);
writer.WriteEndElement();
}
if (ContentLanguage != null)
{
writer.WriteStartElement("Content-Language");
writer.WriteValue(ContentLanguage);
writer.WriteEndElement();
}
if (ContentMD5 != null)
{
writer.WriteStartElement("Content-MD5");
writer.WriteValue(ContentMD5);
writer.WriteEndElement();
}
if (ContentDisposition != null)
{
writer.WriteStartElement("Content-Disposition");
writer.WriteValue(ContentDisposition);
writer.WriteEndElement();
}
if (CacheControl != null)
{
writer.WriteStartElement("Cache-Control");
writer.WriteValue(CacheControl);
writer.WriteEndElement();
}
if (BlobSequenceNumber != null)
{
writer.WriteStartElement("x-ms-blob-sequence-number");
writer.WriteValue(BlobSequenceNumber.Value);
writer.WriteEndElement();
}
if (BlobType != null)
{
writer.WriteStartElement("BlobType");
writer.WriteValue(BlobType.Value.ToSerialString());
writer.WriteEndElement();
}
if (LeaseStatus != null)
{
writer.WriteStartElement("LeaseStatus");
writer.WriteValue(LeaseStatus.Value.ToSerialString());
writer.WriteEndElement();
}
if (LeaseState != null)
{
writer.WriteStartElement("LeaseState");
writer.WriteValue(LeaseState.Value.ToSerialString());
writer.WriteEndElement();
}
if (LeaseDuration != null)
{
writer.WriteStartElement("LeaseDuration");
writer.WriteValue(LeaseDuration.Value.ToSerialString());
writer.WriteEndElement();
}
if (CopyId != null)
{
writer.WriteStartElement("CopyId");
writer.WriteValue(CopyId);
writer.WriteEndElement();
}
if (CopyStatus != null)
{
writer.WriteStartElement("CopyStatus");
writer.WriteValue(CopyStatus.Value.ToSerialString());
writer.WriteEndElement();
}
if (CopySource != null)
{
writer.WriteStartElement("CopySource");
writer.WriteValue(CopySource);
writer.WriteEndElement();
}
if (CopyProgress != null)
{
writer.WriteStartElement("CopyProgress");
writer.WriteValue(CopyProgress);
writer.WriteEndElement();
}
if (CopyCompletionTime != null)
{
writer.WriteStartElement("CopyCompletionTime");
writer.WriteValue(CopyCompletionTime.Value, "R");
writer.WriteEndElement();
}
if (CopyStatusDescription != null)
{
writer.WriteStartElement("CopyStatusDescription");
writer.WriteValue(CopyStatusDescription);
writer.WriteEndElement();
}
if (ServerEncrypted != null)
{
writer.WriteStartElement("ServerEncrypted");
writer.WriteValue(ServerEncrypted.Value);
writer.WriteEndElement();
}
if (IncrementalCopy != null)
{
writer.WriteStartElement("IncrementalCopy");
writer.WriteValue(IncrementalCopy.Value);
writer.WriteEndElement();
}
if (DestinationSnapshot != null)
{
writer.WriteStartElement("DestinationSnapshot");
writer.WriteValue(DestinationSnapshot);
writer.WriteEndElement();
}
if (DeletedTime != null)
{
writer.WriteStartElement("DeletedTime");
writer.WriteValue(DeletedTime.Value, "R");
writer.WriteEndElement();
}
if (RemainingRetentionDays != null)
{
writer.WriteStartElement("RemainingRetentionDays");
writer.WriteValue(RemainingRetentionDays.Value);
writer.WriteEndElement();
}
if (AccessTier != null)
{
writer.WriteStartElement("AccessTier");
writer.WriteValue(AccessTier.Value.ToString());
writer.WriteEndElement();
}
if (AccessTierInferred != null)
{
writer.WriteStartElement("AccessTierInferred");
writer.WriteValue(AccessTierInferred.Value);
writer.WriteEndElement();
}
if (ArchiveStatus != null)
{
writer.WriteStartElement("ArchiveStatus");
writer.WriteValue(ArchiveStatus.Value.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static BlobProperties DeserializeBlobProperties(XElement element)
{
BlobProperties result = default;
result = new BlobProperties(); DateTimeOffset value = default;
var lastModified = element.Element("Last-Modified");
if (lastModified != null)
{
value = lastModified.GetDateTimeOffsetValue("R");
}
result.LastModified = value;
string value0 = default;
var etag = element.Element("Etag");
if (etag != null)
{
value0 = (string)etag;
}
result.Etag = value0;
long? value1 = default;
var contentLength = element.Element("Content-Length");
if (contentLength != null)
{
value1 = (long?)contentLength;
}
result.ContentLength = value1;
string? value2 = default;
var contentType = element.Element("Content-Type");
if (contentType != null)
{
value2 = (string?)contentType;
}
result.ContentType = value2;
string? value3 = default;
var contentEncoding = element.Element("Content-Encoding");
if (contentEncoding != null)
{
value3 = (string?)contentEncoding;
}
result.ContentEncoding = value3;
string? value4 = default;
var contentLanguage = element.Element("Content-Language");
if (contentLanguage != null)
{
value4 = (string?)contentLanguage;
}
result.ContentLanguage = value4;
string? value5 = default;
var contentMD5 = element.Element("Content-MD5");
if (contentMD5 != null)
{
value5 = (string?)contentMD5;
}
result.ContentMD5 = value5;
string? value6 = default;
var contentDisposition = element.Element("Content-Disposition");
if (contentDisposition != null)
{
value6 = (string?)contentDisposition;
}
result.ContentDisposition = value6;
string? value7 = default;
var cacheControl = element.Element("Cache-Control");
if (cacheControl != null)
{
value7 = (string?)cacheControl;
}
result.CacheControl = value7;
int? value8 = default;
var xMsBlobSequenceNumber = element.Element("x-ms-blob-sequence-number");
if (xMsBlobSequenceNumber != null)
{
value8 = (int?)xMsBlobSequenceNumber;
}
result.BlobSequenceNumber = value8;
BlobType? value9 = default;
var blobType = element.Element("BlobType");
if (blobType != null)
{
value9 = blobType.Value.ToBlobType();
}
result.BlobType = value9;
LeaseStatusType? value10 = default;
var leaseStatus = element.Element("LeaseStatus");
if (leaseStatus != null)
{
value10 = leaseStatus.Value.ToLeaseStatusType();
}
result.LeaseStatus = value10;
LeaseStateType? value11 = default;
var leaseState = element.Element("LeaseState");
if (leaseState != null)
{
value11 = leaseState.Value.ToLeaseStateType();
}
result.LeaseState = value11;
LeaseDurationType? value12 = default;
var leaseDuration = element.Element("LeaseDuration");
if (leaseDuration != null)
{
value12 = leaseDuration.Value.ToLeaseDurationType();
}
result.LeaseDuration = value12;
string? value13 = default;
var copyId = element.Element("CopyId");
if (copyId != null)
{
value13 = (string?)copyId;
}
result.CopyId = value13;
CopyStatusType? value14 = default;
var copyStatus = element.Element("CopyStatus");
if (copyStatus != null)
{
value14 = copyStatus.Value.ToCopyStatusType();
}
result.CopyStatus = value14;
string? value15 = default;
var copySource = element.Element("CopySource");
if (copySource != null)
{
value15 = (string?)copySource;
}
result.CopySource = value15;
string? value16 = default;
var copyProgress = element.Element("CopyProgress");
if (copyProgress != null)
{
value16 = (string?)copyProgress;
}
result.CopyProgress = value16;
DateTimeOffset? value17 = default;
var copyCompletionTime = element.Element("CopyCompletionTime");
if (copyCompletionTime != null)
{
value17 = copyCompletionTime.GetDateTimeOffsetValue("R");
}
result.CopyCompletionTime = value17;
string? value18 = default;
var copyStatusDescription = element.Element("CopyStatusDescription");
if (copyStatusDescription != null)
{
value18 = (string?)copyStatusDescription;
}
result.CopyStatusDescription = value18;
bool? value19 = default;
var serverEncrypted = element.Element("ServerEncrypted");
if (serverEncrypted != null)
{
value19 = (bool?)serverEncrypted;
}
result.ServerEncrypted = value19;
bool? value20 = default;
var incrementalCopy = element.Element("IncrementalCopy");
if (incrementalCopy != null)
{
value20 = (bool?)incrementalCopy;
}
result.IncrementalCopy = value20;
string? value21 = default;
var destinationSnapshot = element.Element("DestinationSnapshot");
if (destinationSnapshot != null)
{
value21 = (string?)destinationSnapshot;
}
result.DestinationSnapshot = value21;
DateTimeOffset? value22 = default;
var deletedTime = element.Element("DeletedTime");
if (deletedTime != null)
{
value22 = deletedTime.GetDateTimeOffsetValue("R");
}
result.DeletedTime = value22;
int? value23 = default;
var remainingRetentionDays = element.Element("RemainingRetentionDays");
if (remainingRetentionDays != null)
{
value23 = (int?)remainingRetentionDays;
}
result.RemainingRetentionDays = value23;
AccessTier? value24 = default;
var accessTier = element.Element("AccessTier");
if (accessTier != null)
{
value24 = new AccessTier(accessTier.Value);
}
result.AccessTier = value24;
bool? value25 = default;
var accessTierInferred = element.Element("AccessTierInferred");
if (accessTierInferred != null)
{
value25 = (bool?)accessTierInferred;
}
result.AccessTierInferred = value25;
ArchiveStatus? value26 = default;
var archiveStatus = element.Element("ArchiveStatus");
if (archiveStatus != null)
{
value26 = new ArchiveStatus(archiveStatus.Value);
}
result.ArchiveStatus = value26;
return result;
}
}
}

39
test/TestServerProjects/xml-service/Generated/Models/BlobProperties.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
public partial class BlobProperties
{
public DateTimeOffset LastModified { get; set; }
public string Etag { get; set; }
public long? ContentLength { get; set; }
public string? ContentType { get; set; }
public string? ContentEncoding { get; set; }
public string? ContentLanguage { get; set; }
public string? ContentMD5 { get; set; }
public string? ContentDisposition { get; set; }
public string? CacheControl { get; set; }
public int? BlobSequenceNumber { get; set; }
public BlobType? BlobType { get; set; }
public LeaseStatusType? LeaseStatus { get; set; }
public LeaseStateType? LeaseState { get; set; }
public LeaseDurationType? LeaseDuration { get; set; }
public string? CopyId { get; set; }
public CopyStatusType? CopyStatus { get; set; }
public string? CopySource { get; set; }
public string? CopyProgress { get; set; }
public DateTimeOffset? CopyCompletionTime { get; set; }
public string? CopyStatusDescription { get; set; }
public bool? ServerEncrypted { get; set; }
public bool? IncrementalCopy { get; set; }
public string? DestinationSnapshot { get; set; }
public DateTimeOffset? DeletedTime { get; set; }
public int? RemainingRetentionDays { get; set; }
public AccessTier? AccessTier { get; set; }
public bool? AccessTierInferred { get; set; }
public ArchiveStatus? ArchiveStatus { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
internal static class BlobTypeExtensions
{
public static string ToSerialString(this BlobType value) => value switch
{
BlobType.BlockBlob => "BlockBlob",
BlobType.PageBlob => "PageBlob",
BlobType.AppendBlob => "AppendBlob",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown BlobType value.")
};
public static BlobType ToBlobType(this string value) => value switch
{
"BlockBlob" => BlobType.BlockBlob,
"PageBlob" => BlobType.PageBlob,
"AppendBlob" => BlobType.AppendBlob,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown BlobType value.")
};
}
}

12
test/TestServerProjects/xml-service/Generated/Models/BlobType.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public enum BlobType
{
BlockBlob,
PageBlob,
AppendBlob
}
}

Просмотреть файл

@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Blobs : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (BlobPrefix != null)
{
writer.WritePropertyName("BlobPrefix");
writer.WriteStartArray();
foreach (var item in BlobPrefix)
{
writer.WriteObjectValue(item);
}
writer.WriteEndArray();
}
if (Blob != null)
{
writer.WritePropertyName("Blob");
writer.WriteStartArray();
foreach (var item in Blob)
{
writer.WriteObjectValue(item);
}
writer.WriteEndArray();
}
writer.WriteEndObject();
}
internal static Blobs DeserializeBlobs(JsonElement element)
{
Blobs result = new Blobs();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("BlobPrefix"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.BlobPrefix = new List<BlobPrefix>();
foreach (var item in property.Value.EnumerateArray())
{
result.BlobPrefix.Add(V100.BlobPrefix.DeserializeBlobPrefix(item));
}
continue;
}
if (property.NameEquals("Blob"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Blob = new List<Blob>();
foreach (var item in property.Value.EnumerateArray())
{
result.Blob.Add(V100.Blob.DeserializeBlob(item));
}
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Blobs");
if (BlobPrefix != null)
{
foreach (var item in BlobPrefix)
{
writer.WriteObjectValue(item, "BlobPrefix");
}
}
if (Blob != null)
{
foreach (var item in Blob)
{
writer.WriteObjectValue(item, "Blob");
}
}
writer.WriteEndElement();
}
internal static Blobs DeserializeBlobs(XElement element)
{
Blobs result = default;
result = new Blobs(); result.BlobPrefix = new List<BlobPrefix>();
foreach (var e in element.Elements("BlobPrefix"))
{
BlobPrefix value = default;
value = V100.BlobPrefix.DeserializeBlobPrefix(e);
result.BlobPrefix.Add(value);
}
result.Blob = new List<Blob>();
foreach (var e0 in element.Elements("Blob"))
{
Blob value = default;
value = V100.Blob.DeserializeBlob(e0);
result.Blob.Add(value);
}
return result;
}
}
}

13
test/TestServerProjects/xml-service/Generated/Models/Blobs.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace xml_service.Models.V100
{
public partial class Blobs
{
public ICollection<BlobPrefix>? BlobPrefix { get; set; }
public ICollection<Blob>? Blob { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class ComplexTypeNoMeta : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (ID != null)
{
writer.WritePropertyName("ID");
writer.WriteStringValue(ID);
}
writer.WriteEndObject();
}
internal static ComplexTypeNoMeta DeserializeComplexTypeNoMeta(JsonElement element)
{
ComplexTypeNoMeta result = new ComplexTypeNoMeta();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("ID"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ID = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "ComplexTypeNoMeta");
if (ID != null)
{
writer.WriteStartElement("ID");
writer.WriteValue(ID);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static ComplexTypeNoMeta DeserializeComplexTypeNoMeta(XElement element)
{
ComplexTypeNoMeta result = default;
result = new ComplexTypeNoMeta(); string? value = default;
var iD = element.Element("ID");
if (iD != null)
{
value = (string?)iD;
}
result.ID = value;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class ComplexTypeNoMeta
{
public string? ID { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class ComplexTypeWithMeta : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (ID != null)
{
writer.WritePropertyName("ID");
writer.WriteStringValue(ID);
}
writer.WriteEndObject();
}
internal static ComplexTypeWithMeta DeserializeComplexTypeWithMeta(JsonElement element)
{
ComplexTypeWithMeta result = new ComplexTypeWithMeta();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("ID"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.ID = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "XMLComplexTypeWithMeta");
if (ID != null)
{
writer.WriteStartElement("ID");
writer.WriteValue(ID);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static ComplexTypeWithMeta DeserializeComplexTypeWithMeta(XElement element)
{
ComplexTypeWithMeta result = default;
result = new ComplexTypeWithMeta(); string? value = default;
var iD = element.Element("ID");
if (iD != null)
{
value = (string?)iD;
}
result.ID = value;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class ComplexTypeWithMeta
{
public string? ID { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,116 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Container : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Name");
writer.WriteStringValue(Name);
writer.WritePropertyName("Properties");
writer.WriteObjectValue(Properties);
if (Metadata != null)
{
writer.WritePropertyName("Metadata");
writer.WriteStartObject();
foreach (var item in Metadata)
{
writer.WritePropertyName(item.Key);
writer.WriteStringValue(item.Value);
}
writer.WriteEndObject();
}
writer.WriteEndObject();
}
internal static Container DeserializeContainer(JsonElement element)
{
Container result = new Container();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Name"))
{
result.Name = property.Value.GetString();
continue;
}
if (property.NameEquals("Properties"))
{
result.Properties = ContainerProperties.DeserializeContainerProperties(property.Value);
continue;
}
if (property.NameEquals("Metadata"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Metadata = new Dictionary<string, string>();
foreach (var property0 in property.Value.EnumerateObject())
{
result.Metadata.Add(property0.Name, property0.Value.GetString());
}
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Container");
writer.WriteStartElement("Name");
writer.WriteValue(Name);
writer.WriteEndElement();
writer.WriteObjectValue(Properties, "Properties");
if (Metadata != null)
{
foreach (var pair in Metadata)
{
writer.WriteStartElement("!dictionary-item");
writer.WriteValue(pair.Value);
writer.WriteEndElement();
}
}
writer.WriteEndElement();
}
internal static Container DeserializeContainer(XElement element)
{
Container result = default;
result = new Container(); string value = default;
var name = element.Element("Name");
if (name != null)
{
value = (string)name;
}
result.Name = value;
ContainerProperties value0 = default;
var properties = element.Element("Properties");
if (properties != null)
{
value0 = ContainerProperties.DeserializeContainerProperties(properties);
}
result.Properties = value0;
IDictionary<string, string>? value1 = default;
var metadata = element.Element("Metadata");
if (metadata != null)
{
value1 = new Dictionary<string, string>(); var elements = metadata.Elements();
foreach (var e in elements)
{
string value2 = default;
value2 = (string)e;
value1.Add(e.Name.LocalName, value2);
}
}
result.Metadata = value1;
return result;
}
}
}

14
test/TestServerProjects/xml-service/Generated/Models/Container.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace xml_service.Models.V100
{
public partial class Container
{
public string Name { get; set; }
public ContainerProperties Properties { get; set; } = new ContainerProperties();
public IDictionary<string, string>? Metadata { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,180 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class ContainerProperties : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Last-Modified");
writer.WriteStringValue(LastModified, "R");
writer.WritePropertyName("Etag");
writer.WriteStringValue(Etag);
if (LeaseStatus != null)
{
writer.WritePropertyName("LeaseStatus");
writer.WriteStringValue(LeaseStatus.Value.ToSerialString());
}
if (LeaseState != null)
{
writer.WritePropertyName("LeaseState");
writer.WriteStringValue(LeaseState.Value.ToSerialString());
}
if (LeaseDuration != null)
{
writer.WritePropertyName("LeaseDuration");
writer.WriteStringValue(LeaseDuration.Value.ToSerialString());
}
if (PublicAccess != null)
{
writer.WritePropertyName("PublicAccess");
writer.WriteStringValue(PublicAccess.Value.ToString());
}
writer.WriteEndObject();
}
internal static ContainerProperties DeserializeContainerProperties(JsonElement element)
{
ContainerProperties result = new ContainerProperties();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Last-Modified"))
{
result.LastModified = property.Value.GetDateTimeOffset("R");
continue;
}
if (property.NameEquals("Etag"))
{
result.Etag = property.Value.GetString();
continue;
}
if (property.NameEquals("LeaseStatus"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseStatus = property.Value.GetString().ToLeaseStatusType();
continue;
}
if (property.NameEquals("LeaseState"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseState = property.Value.GetString().ToLeaseStateType();
continue;
}
if (property.NameEquals("LeaseDuration"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.LeaseDuration = property.Value.GetString().ToLeaseDurationType();
continue;
}
if (property.NameEquals("PublicAccess"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.PublicAccess = new PublicAccessType(property.Value.GetString());
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "ContainerProperties");
writer.WriteStartElement("Last-Modified");
writer.WriteValue(LastModified, "R");
writer.WriteEndElement();
writer.WriteStartElement("Etag");
writer.WriteValue(Etag);
writer.WriteEndElement();
if (LeaseStatus != null)
{
writer.WriteStartElement("LeaseStatus");
writer.WriteValue(LeaseStatus.Value.ToSerialString());
writer.WriteEndElement();
}
if (LeaseState != null)
{
writer.WriteStartElement("LeaseState");
writer.WriteValue(LeaseState.Value.ToSerialString());
writer.WriteEndElement();
}
if (LeaseDuration != null)
{
writer.WriteStartElement("LeaseDuration");
writer.WriteValue(LeaseDuration.Value.ToSerialString());
writer.WriteEndElement();
}
if (PublicAccess != null)
{
writer.WriteStartElement("PublicAccess");
writer.WriteValue(PublicAccess.Value.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static ContainerProperties DeserializeContainerProperties(XElement element)
{
ContainerProperties result = default;
result = new ContainerProperties(); DateTimeOffset value = default;
var lastModified = element.Element("Last-Modified");
if (lastModified != null)
{
value = lastModified.GetDateTimeOffsetValue("R");
}
result.LastModified = value;
string value0 = default;
var etag = element.Element("Etag");
if (etag != null)
{
value0 = (string)etag;
}
result.Etag = value0;
LeaseStatusType? value1 = default;
var leaseStatus = element.Element("LeaseStatus");
if (leaseStatus != null)
{
value1 = leaseStatus.Value.ToLeaseStatusType();
}
result.LeaseStatus = value1;
LeaseStateType? value2 = default;
var leaseState = element.Element("LeaseState");
if (leaseState != null)
{
value2 = leaseState.Value.ToLeaseStateType();
}
result.LeaseState = value2;
LeaseDurationType? value3 = default;
var leaseDuration = element.Element("LeaseDuration");
if (leaseDuration != null)
{
value3 = leaseDuration.Value.ToLeaseDurationType();
}
result.LeaseDuration = value3;
PublicAccessType? value4 = default;
var publicAccess = element.Element("PublicAccess");
if (publicAccess != null)
{
value4 = new PublicAccessType(publicAccess.Value);
}
result.PublicAccess = value4;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
public partial class ContainerProperties
{
public DateTimeOffset LastModified { get; set; }
public string Etag { get; set; }
public LeaseStatusType? LeaseStatus { get; set; }
public LeaseStateType? LeaseState { get; set; }
public LeaseDurationType? LeaseDuration { get; set; }
public PublicAccessType? PublicAccess { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
internal static class CopyStatusTypeExtensions
{
public static string ToSerialString(this CopyStatusType value) => value switch
{
CopyStatusType.Pending => "pending",
CopyStatusType.Success => "success",
CopyStatusType.Aborted => "aborted",
CopyStatusType.Failed => "failed",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown CopyStatusType value.")
};
public static CopyStatusType ToCopyStatusType(this string value) => value switch
{
"pending" => CopyStatusType.Pending,
"success" => CopyStatusType.Success,
"aborted" => CopyStatusType.Aborted,
"failed" => CopyStatusType.Failed,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown CopyStatusType value.")
};
}
}

13
test/TestServerProjects/xml-service/Generated/Models/CopyStatusType.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public enum CopyStatusType
{
Pending,
Success,
Aborted,
Failed
}
}

Просмотреть файл

@ -0,0 +1,122 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class CorsRule : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("AllowedOrigins");
writer.WriteStringValue(AllowedOrigins);
writer.WritePropertyName("AllowedMethods");
writer.WriteStringValue(AllowedMethods);
writer.WritePropertyName("AllowedHeaders");
writer.WriteStringValue(AllowedHeaders);
writer.WritePropertyName("ExposedHeaders");
writer.WriteStringValue(ExposedHeaders);
writer.WritePropertyName("MaxAgeInSeconds");
writer.WriteNumberValue(MaxAgeInSeconds);
writer.WriteEndObject();
}
internal static CorsRule DeserializeCorsRule(JsonElement element)
{
CorsRule result = new CorsRule();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("AllowedOrigins"))
{
result.AllowedOrigins = property.Value.GetString();
continue;
}
if (property.NameEquals("AllowedMethods"))
{
result.AllowedMethods = property.Value.GetString();
continue;
}
if (property.NameEquals("AllowedHeaders"))
{
result.AllowedHeaders = property.Value.GetString();
continue;
}
if (property.NameEquals("ExposedHeaders"))
{
result.ExposedHeaders = property.Value.GetString();
continue;
}
if (property.NameEquals("MaxAgeInSeconds"))
{
result.MaxAgeInSeconds = property.Value.GetInt32();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "CorsRule");
writer.WriteStartElement("AllowedOrigins");
writer.WriteValue(AllowedOrigins);
writer.WriteEndElement();
writer.WriteStartElement("AllowedMethods");
writer.WriteValue(AllowedMethods);
writer.WriteEndElement();
writer.WriteStartElement("AllowedHeaders");
writer.WriteValue(AllowedHeaders);
writer.WriteEndElement();
writer.WriteStartElement("ExposedHeaders");
writer.WriteValue(ExposedHeaders);
writer.WriteEndElement();
writer.WriteStartElement("MaxAgeInSeconds");
writer.WriteValue(MaxAgeInSeconds);
writer.WriteEndElement();
writer.WriteEndElement();
}
internal static CorsRule DeserializeCorsRule(XElement element)
{
CorsRule result = default;
result = new CorsRule(); string value = default;
var allowedOrigins = element.Element("AllowedOrigins");
if (allowedOrigins != null)
{
value = (string)allowedOrigins;
}
result.AllowedOrigins = value;
string value0 = default;
var allowedMethods = element.Element("AllowedMethods");
if (allowedMethods != null)
{
value0 = (string)allowedMethods;
}
result.AllowedMethods = value0;
string value1 = default;
var allowedHeaders = element.Element("AllowedHeaders");
if (allowedHeaders != null)
{
value1 = (string)allowedHeaders;
}
result.AllowedHeaders = value1;
string value2 = default;
var exposedHeaders = element.Element("ExposedHeaders");
if (exposedHeaders != null)
{
value2 = (string)exposedHeaders;
}
result.ExposedHeaders = value2;
int value3 = default;
var maxAgeInSeconds = element.Element("MaxAgeInSeconds");
if (maxAgeInSeconds != null)
{
value3 = (int)maxAgeInSeconds;
}
result.MaxAgeInSeconds = value3;
return result;
}
}
}

14
test/TestServerProjects/xml-service/Generated/Models/CorsRule.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class CorsRule
{
public string AllowedOrigins { get; set; }
public string AllowedMethods { get; set; }
public string AllowedHeaders { get; set; }
public string ExposedHeaders { get; set; }
public int MaxAgeInSeconds { get; set; }
}
}

Просмотреть файл

@ -2,11 +2,13 @@
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace custom_baseUrl_more_options.Models.V100
namespace xml_service.Models.V100
{
public partial class Error : IUtf8JsonSerializable
public partial class Error : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
@ -49,5 +51,41 @@ namespace custom_baseUrl_more_options.Models.V100
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Error");
if (Status != null)
{
writer.WriteStartElement("status");
writer.WriteValue(Status.Value);
writer.WriteEndElement();
}
if (Message != null)
{
writer.WriteStartElement("message");
writer.WriteValue(Message);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static Error DeserializeError(XElement element)
{
Error result = default;
result = new Error(); int? value = default;
var status = element.Element("status");
if (status != null)
{
value = (int?)status;
}
result.Status = value;
string? value0 = default;
var message = element.Element("message");
if (message != null)
{
value0 = (string?)message;
}
result.Message = value0;
return result;
}
}
}

11
test/TestServerProjects/xml-service/Generated/Models/Error.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class Error
{
public int? Status { get; set; }
public string? Message { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class JSONInput : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Id != null)
{
writer.WritePropertyName("id");
writer.WriteNumberValue(Id.Value);
}
writer.WriteEndObject();
}
internal static JSONInput DeserializeJSONInput(JsonElement element)
{
JSONInput result = new JSONInput();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("id"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Id = property.Value.GetInt32();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "JSONInput");
if (Id != null)
{
writer.WriteStartElement("id");
writer.WriteValue(Id.Value);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static JSONInput DeserializeJSONInput(XElement element)
{
JSONInput result = default;
result = new JSONInput(); int? value = default;
var id = element.Element("id");
if (id != null)
{
value = (int?)id;
}
result.Id = value;
return result;
}
}
}

10
test/TestServerProjects/xml-service/Generated/Models/JSONInput.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class JSONInput
{
public int? Id { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class JSONOutput : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Id != null)
{
writer.WritePropertyName("id");
writer.WriteNumberValue(Id.Value);
}
writer.WriteEndObject();
}
internal static JSONOutput DeserializeJSONOutput(JsonElement element)
{
JSONOutput result = new JSONOutput();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("id"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Id = property.Value.GetInt32();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "JSONOutput");
if (Id != null)
{
writer.WriteStartElement("id");
writer.WriteValue(Id.Value);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static JSONOutput DeserializeJSONOutput(XElement element)
{
JSONOutput result = default;
result = new JSONOutput(); int? value = default;
var id = element.Element("id");
if (id != null)
{
value = (int?)id;
}
result.Id = value;
return result;
}
}
}

10
test/TestServerProjects/xml-service/Generated/Models/JSONOutput.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class JSONOutput
{
public int? Id { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
internal static class LeaseDurationTypeExtensions
{
public static string ToSerialString(this LeaseDurationType value) => value switch
{
LeaseDurationType.Infinite => "infinite",
LeaseDurationType.Fixed => "fixed",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseDurationType value.")
};
public static LeaseDurationType ToLeaseDurationType(this string value) => value switch
{
"infinite" => LeaseDurationType.Infinite,
"fixed" => LeaseDurationType.Fixed,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseDurationType value.")
};
}
}

Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public enum LeaseDurationType
{
Infinite,
Fixed
}
}

Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
internal static class LeaseStateTypeExtensions
{
public static string ToSerialString(this LeaseStateType value) => value switch
{
LeaseStateType.Available => "available",
LeaseStateType.Leased => "leased",
LeaseStateType.Expired => "expired",
LeaseStateType.Breaking => "breaking",
LeaseStateType.Broken => "broken",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseStateType value.")
};
public static LeaseStateType ToLeaseStateType(this string value) => value switch
{
"available" => LeaseStateType.Available,
"leased" => LeaseStateType.Leased,
"expired" => LeaseStateType.Expired,
"breaking" => LeaseStateType.Breaking,
"broken" => LeaseStateType.Broken,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseStateType value.")
};
}
}

14
test/TestServerProjects/xml-service/Generated/Models/LeaseStateType.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public enum LeaseStateType
{
Available,
Leased,
Expired,
Breaking,
Broken
}
}

Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace xml_service.Models.V100
{
internal static class LeaseStatusTypeExtensions
{
public static string ToSerialString(this LeaseStatusType value) => value switch
{
LeaseStatusType.Locked => "locked",
LeaseStatusType.Unlocked => "unlocked",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseStatusType value.")
};
public static LeaseStatusType ToLeaseStatusType(this string value) => value switch
{
"locked" => LeaseStatusType.Locked,
"unlocked" => LeaseStatusType.Unlocked,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown LeaseStatusType value.")
};
}
}

11
test/TestServerProjects/xml-service/Generated/Models/LeaseStatusType.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public enum LeaseStatusType
{
Locked,
Unlocked
}
}

Просмотреть файл

@ -0,0 +1,167 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class ListBlobsResponse : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("ServiceEndpoint");
writer.WriteStringValue(ServiceEndpoint);
writer.WritePropertyName("ContainerName");
writer.WriteStringValue(ContainerName);
writer.WritePropertyName("Prefix");
writer.WriteStringValue(Prefix);
writer.WritePropertyName("Marker");
writer.WriteStringValue(Marker);
writer.WritePropertyName("MaxResults");
writer.WriteNumberValue(MaxResults);
writer.WritePropertyName("Delimiter");
writer.WriteStringValue(Delimiter);
writer.WritePropertyName("Blobs");
writer.WriteObjectValue(Blobs);
writer.WritePropertyName("NextMarker");
writer.WriteStringValue(NextMarker);
writer.WriteEndObject();
}
internal static ListBlobsResponse DeserializeListBlobsResponse(JsonElement element)
{
ListBlobsResponse result = new ListBlobsResponse();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("ServiceEndpoint"))
{
result.ServiceEndpoint = property.Value.GetString();
continue;
}
if (property.NameEquals("ContainerName"))
{
result.ContainerName = property.Value.GetString();
continue;
}
if (property.NameEquals("Prefix"))
{
result.Prefix = property.Value.GetString();
continue;
}
if (property.NameEquals("Marker"))
{
result.Marker = property.Value.GetString();
continue;
}
if (property.NameEquals("MaxResults"))
{
result.MaxResults = property.Value.GetInt32();
continue;
}
if (property.NameEquals("Delimiter"))
{
result.Delimiter = property.Value.GetString();
continue;
}
if (property.NameEquals("Blobs"))
{
result.Blobs = Blobs.DeserializeBlobs(property.Value);
continue;
}
if (property.NameEquals("NextMarker"))
{
result.NextMarker = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "EnumerationResults");
writer.WriteStartAttribute("ServiceEndpoint");
writer.WriteValue(ServiceEndpoint);
writer.WriteEndAttribute();
writer.WriteStartAttribute("ContainerName");
writer.WriteValue(ContainerName);
writer.WriteEndAttribute();
writer.WriteStartElement("Prefix");
writer.WriteValue(Prefix);
writer.WriteEndElement();
writer.WriteStartElement("Marker");
writer.WriteValue(Marker);
writer.WriteEndElement();
writer.WriteStartElement("MaxResults");
writer.WriteValue(MaxResults);
writer.WriteEndElement();
writer.WriteStartElement("Delimiter");
writer.WriteValue(Delimiter);
writer.WriteEndElement();
writer.WriteObjectValue(Blobs, "Blobs");
writer.WriteStartElement("NextMarker");
writer.WriteValue(NextMarker);
writer.WriteEndElement();
writer.WriteEndElement();
}
internal static ListBlobsResponse DeserializeListBlobsResponse(XElement element)
{
ListBlobsResponse result = default;
result = new ListBlobsResponse(); var serviceEndpoint = element.Attribute("ServiceEndpoint");
if (serviceEndpoint != null)
{
result.ServiceEndpoint = (string)serviceEndpoint;
}
var containerName = element.Attribute("ContainerName");
if (containerName != null)
{
result.ContainerName = (string)containerName;
}
string value = default;
var prefix = element.Element("Prefix");
if (prefix != null)
{
value = (string)prefix;
}
result.Prefix = value;
string value0 = default;
var marker = element.Element("Marker");
if (marker != null)
{
value0 = (string)marker;
}
result.Marker = value0;
int value1 = default;
var maxResults = element.Element("MaxResults");
if (maxResults != null)
{
value1 = (int)maxResults;
}
result.MaxResults = value1;
string value2 = default;
var delimiter = element.Element("Delimiter");
if (delimiter != null)
{
value2 = (string)delimiter;
}
result.Delimiter = value2;
Blobs value3 = default;
var blobs = element.Element("Blobs");
if (blobs != null)
{
value3 = Blobs.DeserializeBlobs(blobs);
}
result.Blobs = value3;
string value4 = default;
var nextMarker = element.Element("NextMarker");
if (nextMarker != null)
{
value4 = (string)nextMarker;
}
result.NextMarker = value4;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class ListBlobsResponse
{
public string ServiceEndpoint { get; set; }
public string ContainerName { get; set; }
public string Prefix { get; set; }
public string Marker { get; set; }
public int MaxResults { get; set; }
public string Delimiter { get; set; }
public Blobs Blobs { get; set; } = new Blobs();
public string NextMarker { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,174 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class ListContainersResponse : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("ServiceEndpoint");
writer.WriteStringValue(ServiceEndpoint);
writer.WritePropertyName("Prefix");
writer.WriteStringValue(Prefix);
if (Marker != null)
{
writer.WritePropertyName("Marker");
writer.WriteStringValue(Marker);
}
writer.WritePropertyName("MaxResults");
writer.WriteNumberValue(MaxResults);
if (Containers != null)
{
writer.WritePropertyName("Containers");
writer.WriteStartArray();
foreach (var item in Containers)
{
writer.WriteObjectValue(item);
}
writer.WriteEndArray();
}
writer.WritePropertyName("NextMarker");
writer.WriteStringValue(NextMarker);
writer.WriteEndObject();
}
internal static ListContainersResponse DeserializeListContainersResponse(JsonElement element)
{
ListContainersResponse result = new ListContainersResponse();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("ServiceEndpoint"))
{
result.ServiceEndpoint = property.Value.GetString();
continue;
}
if (property.NameEquals("Prefix"))
{
result.Prefix = property.Value.GetString();
continue;
}
if (property.NameEquals("Marker"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Marker = property.Value.GetString();
continue;
}
if (property.NameEquals("MaxResults"))
{
result.MaxResults = property.Value.GetInt32();
continue;
}
if (property.NameEquals("Containers"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Containers = new List<Container>();
foreach (var item in property.Value.EnumerateArray())
{
result.Containers.Add(Container.DeserializeContainer(item));
}
continue;
}
if (property.NameEquals("NextMarker"))
{
result.NextMarker = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "EnumerationResults");
writer.WriteStartAttribute("ServiceEndpoint");
writer.WriteValue(ServiceEndpoint);
writer.WriteEndAttribute();
writer.WriteStartElement("Prefix");
writer.WriteValue(Prefix);
writer.WriteEndElement();
if (Marker != null)
{
writer.WriteStartElement("Marker");
writer.WriteValue(Marker);
writer.WriteEndElement();
}
writer.WriteStartElement("MaxResults");
writer.WriteValue(MaxResults);
writer.WriteEndElement();
writer.WriteStartElement("NextMarker");
writer.WriteValue(NextMarker);
writer.WriteEndElement();
if (Containers != null)
{
writer.WriteStartElement("Containers");
foreach (var item in Containers)
{
writer.WriteObjectValue(item, "Container");
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static ListContainersResponse DeserializeListContainersResponse(XElement element)
{
ListContainersResponse result = default;
result = new ListContainersResponse(); var serviceEndpoint = element.Attribute("ServiceEndpoint");
if (serviceEndpoint != null)
{
result.ServiceEndpoint = (string)serviceEndpoint;
}
string value = default;
var prefix = element.Element("Prefix");
if (prefix != null)
{
value = (string)prefix;
}
result.Prefix = value;
string? value0 = default;
var marker = element.Element("Marker");
if (marker != null)
{
value0 = (string?)marker;
}
result.Marker = value0;
int value1 = default;
var maxResults = element.Element("MaxResults");
if (maxResults != null)
{
value1 = (int)maxResults;
}
result.MaxResults = value1;
string value2 = default;
var nextMarker = element.Element("NextMarker");
if (nextMarker != null)
{
value2 = (string)nextMarker;
}
result.NextMarker = value2;
var containers = element.Element("Containers");
if (containers != null)
{
result.Containers = new List<Container>();
foreach (var e in containers.Elements("Container"))
{
Container value3 = default;
value3 = Container.DeserializeContainer(e);
result.Containers.Add(value3);
}
}
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace xml_service.Models.V100
{
public partial class ListContainersResponse
{
public string ServiceEndpoint { get; set; }
public string Prefix { get; set; }
public string? Marker { get; set; }
public int MaxResults { get; set; }
public ICollection<Container>? Containers { get; set; }
public string NextMarker { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,120 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Logging : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Version");
writer.WriteStringValue(Version);
writer.WritePropertyName("Delete");
writer.WriteBooleanValue(Delete);
writer.WritePropertyName("Read");
writer.WriteBooleanValue(Read);
writer.WritePropertyName("Write");
writer.WriteBooleanValue(Write);
writer.WritePropertyName("RetentionPolicy");
writer.WriteObjectValue(RetentionPolicy);
writer.WriteEndObject();
}
internal static Logging DeserializeLogging(JsonElement element)
{
Logging result = new Logging();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Version"))
{
result.Version = property.Value.GetString();
continue;
}
if (property.NameEquals("Delete"))
{
result.Delete = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("Read"))
{
result.Read = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("Write"))
{
result.Write = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("RetentionPolicy"))
{
result.RetentionPolicy = RetentionPolicy.DeserializeRetentionPolicy(property.Value);
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Logging");
writer.WriteStartElement("Version");
writer.WriteValue(Version);
writer.WriteEndElement();
writer.WriteStartElement("Delete");
writer.WriteValue(Delete);
writer.WriteEndElement();
writer.WriteStartElement("Read");
writer.WriteValue(Read);
writer.WriteEndElement();
writer.WriteStartElement("Write");
writer.WriteValue(Write);
writer.WriteEndElement();
writer.WriteObjectValue(RetentionPolicy, "RetentionPolicy");
writer.WriteEndElement();
}
internal static Logging DeserializeLogging(XElement element)
{
Logging result = default;
result = new Logging(); string value = default;
var version = element.Element("Version");
if (version != null)
{
value = (string)version;
}
result.Version = value;
bool value0 = default;
var delete = element.Element("Delete");
if (delete != null)
{
value0 = (bool)delete;
}
result.Delete = value0;
bool value1 = default;
var read = element.Element("Read");
if (read != null)
{
value1 = (bool)read;
}
result.Read = value1;
bool value2 = default;
var write = element.Element("Write");
if (write != null)
{
value2 = (bool)write;
}
result.Write = value2;
RetentionPolicy value3 = default;
var retentionPolicy = element.Element("RetentionPolicy");
if (retentionPolicy != null)
{
value3 = RetentionPolicy.DeserializeRetentionPolicy(retentionPolicy);
}
result.RetentionPolicy = value3;
return result;
}
}
}

14
test/TestServerProjects/xml-service/Generated/Models/Logging.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class Logging
{
public string Version { get; set; }
public bool Delete { get; set; }
public bool Read { get; set; }
public bool Write { get; set; }
public RetentionPolicy RetentionPolicy { get; set; } = new RetentionPolicy();
}
}

Просмотреть файл

@ -0,0 +1,133 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class Metrics : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Version != null)
{
writer.WritePropertyName("Version");
writer.WriteStringValue(Version);
}
writer.WritePropertyName("Enabled");
writer.WriteBooleanValue(Enabled);
if (IncludeAPIs != null)
{
writer.WritePropertyName("IncludeAPIs");
writer.WriteBooleanValue(IncludeAPIs.Value);
}
if (RetentionPolicy != null)
{
writer.WritePropertyName("RetentionPolicy");
writer.WriteObjectValue(RetentionPolicy);
}
writer.WriteEndObject();
}
internal static Metrics DeserializeMetrics(JsonElement element)
{
Metrics result = new Metrics();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Version"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Version = property.Value.GetString();
continue;
}
if (property.NameEquals("Enabled"))
{
result.Enabled = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("IncludeAPIs"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.IncludeAPIs = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("RetentionPolicy"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.RetentionPolicy = RetentionPolicy.DeserializeRetentionPolicy(property.Value);
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "Metrics");
if (Version != null)
{
writer.WriteStartElement("Version");
writer.WriteValue(Version);
writer.WriteEndElement();
}
writer.WriteStartElement("Enabled");
writer.WriteValue(Enabled);
writer.WriteEndElement();
if (IncludeAPIs != null)
{
writer.WriteStartElement("IncludeAPIs");
writer.WriteValue(IncludeAPIs.Value);
writer.WriteEndElement();
}
if (RetentionPolicy != null)
{
writer.WriteObjectValue(RetentionPolicy, "RetentionPolicy");
}
writer.WriteEndElement();
}
internal static Metrics DeserializeMetrics(XElement element)
{
Metrics result = default;
result = new Metrics(); string? value = default;
var version = element.Element("Version");
if (version != null)
{
value = (string?)version;
}
result.Version = value;
bool value0 = default;
var enabled = element.Element("Enabled");
if (enabled != null)
{
value0 = (bool)enabled;
}
result.Enabled = value0;
bool? value1 = default;
var includeAPIs = element.Element("IncludeAPIs");
if (includeAPIs != null)
{
value1 = (bool?)includeAPIs;
}
result.IncludeAPIs = value1;
RetentionPolicy? value2 = default;
var retentionPolicy = element.Element("RetentionPolicy");
if (retentionPolicy != null)
{
value2 = RetentionPolicy.DeserializeRetentionPolicy(retentionPolicy);
}
result.RetentionPolicy = value2;
return result;
}
}
}

13
test/TestServerProjects/xml-service/Generated/Models/Metrics.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class Metrics
{
public string? Version { get; set; }
public bool Enabled { get; set; }
public bool? IncludeAPIs { get; set; }
public RetentionPolicy? RetentionPolicy { get; set; }
}
}

35
test/TestServerProjects/xml-service/Generated/Models/PublicAccessType.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace xml_service.Models.V100
{
public readonly partial struct PublicAccessType : IEquatable<PublicAccessType>
{
private readonly string? _value;
public PublicAccessType(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string ContainerValue = "container";
private const string BlobValue = "blob";
public static PublicAccessType Container { get; } = new PublicAccessType(ContainerValue);
public static PublicAccessType Blob { get; } = new PublicAccessType(BlobValue);
public static bool operator ==(PublicAccessType left, PublicAccessType right) => left.Equals(right);
public static bool operator !=(PublicAccessType left, PublicAccessType right) => !left.Equals(right);
public static implicit operator PublicAccessType(string value) => new PublicAccessType(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is PublicAccessType other && Equals(other);
public bool Equals(PublicAccessType other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
}
}

Просмотреть файл

@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class RetentionPolicy : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("Enabled");
writer.WriteBooleanValue(Enabled);
if (Days != null)
{
writer.WritePropertyName("Days");
writer.WriteNumberValue(Days.Value);
}
writer.WriteEndObject();
}
internal static RetentionPolicy DeserializeRetentionPolicy(JsonElement element)
{
RetentionPolicy result = new RetentionPolicy();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("Enabled"))
{
result.Enabled = property.Value.GetBoolean();
continue;
}
if (property.NameEquals("Days"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Days = property.Value.GetInt32();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "RetentionPolicy");
writer.WriteStartElement("Enabled");
writer.WriteValue(Enabled);
writer.WriteEndElement();
if (Days != null)
{
writer.WriteStartElement("Days");
writer.WriteValue(Days.Value);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static RetentionPolicy DeserializeRetentionPolicy(XElement element)
{
RetentionPolicy result = default;
result = new RetentionPolicy(); bool value = default;
var enabled = element.Element("Enabled");
if (enabled != null)
{
value = (bool)enabled;
}
result.Enabled = value;
int? value0 = default;
var days = element.Element("Days");
if (days != null)
{
value0 = (int?)days;
}
result.Days = value0;
return result;
}
}
}

11
test/TestServerProjects/xml-service/Generated/Models/RetentionPolicy.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class RetentionPolicy
{
public bool Enabled { get; set; }
public int? Days { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class RootWithRefAndMeta : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (RefToModel != null)
{
writer.WritePropertyName("RefToModel");
writer.WriteObjectValue(RefToModel);
}
if (Something != null)
{
writer.WritePropertyName("Something");
writer.WriteStringValue(Something);
}
writer.WriteEndObject();
}
internal static RootWithRefAndMeta DeserializeRootWithRefAndMeta(JsonElement element)
{
RootWithRefAndMeta result = new RootWithRefAndMeta();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("RefToModel"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.RefToModel = ComplexTypeWithMeta.DeserializeComplexTypeWithMeta(property.Value);
continue;
}
if (property.NameEquals("Something"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Something = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "RootWithRefAndMeta");
if (RefToModel != null)
{
writer.WriteObjectValue(RefToModel, "XMLComplexTypeWithMeta");
}
if (Something != null)
{
writer.WriteStartElement("Something");
writer.WriteValue(Something);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static RootWithRefAndMeta DeserializeRootWithRefAndMeta(XElement element)
{
RootWithRefAndMeta result = default;
result = new RootWithRefAndMeta(); ComplexTypeWithMeta? value = default;
var xMLComplexTypeWithMeta = element.Element("XMLComplexTypeWithMeta");
if (xMLComplexTypeWithMeta != null)
{
value = ComplexTypeWithMeta.DeserializeComplexTypeWithMeta(xMLComplexTypeWithMeta);
}
result.RefToModel = value;
string? value0 = default;
var something = element.Element("Something");
if (something != null)
{
value0 = (string?)something;
}
result.Something = value0;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class RootWithRefAndMeta
{
public ComplexTypeWithMeta? RefToModel { get; set; }
public string? Something { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;
namespace xml_service.Models.V100
{
public partial class RootWithRefAndNoMeta : IUtf8JsonSerializable, IXmlSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (RefToModel != null)
{
writer.WritePropertyName("RefToModel");
writer.WriteObjectValue(RefToModel);
}
if (Something != null)
{
writer.WritePropertyName("Something");
writer.WriteStringValue(Something);
}
writer.WriteEndObject();
}
internal static RootWithRefAndNoMeta DeserializeRootWithRefAndNoMeta(JsonElement element)
{
RootWithRefAndNoMeta result = new RootWithRefAndNoMeta();
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("RefToModel"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.RefToModel = ComplexTypeNoMeta.DeserializeComplexTypeNoMeta(property.Value);
continue;
}
if (property.NameEquals("Something"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
result.Something = property.Value.GetString();
continue;
}
}
return result;
}
void IXmlSerializable.Write(XmlWriter writer, string nameHint)
{
writer.WriteStartElement(nameHint ?? "RootWithRefAndNoMeta");
if (RefToModel != null)
{
writer.WriteObjectValue(RefToModel, "RefToModel");
}
if (Something != null)
{
writer.WriteStartElement("Something");
writer.WriteValue(Something);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
internal static RootWithRefAndNoMeta DeserializeRootWithRefAndNoMeta(XElement element)
{
RootWithRefAndNoMeta result = default;
result = new RootWithRefAndNoMeta(); ComplexTypeNoMeta? value = default;
var refToModel = element.Element("RefToModel");
if (refToModel != null)
{
value = ComplexTypeNoMeta.DeserializeComplexTypeNoMeta(refToModel);
}
result.RefToModel = value;
string? value0 = default;
var something = element.Element("Something");
if (something != null)
{
value0 = (string?)something;
}
result.Something = value0;
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace xml_service.Models.V100
{
public partial class RootWithRefAndNoMeta
{
public ComplexTypeNoMeta? RefToModel { get; set; }
public string? Something { get; set; }
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше