This PR populates the cast methods that are currently generated for
models. Additional unit tests and functional tests were also added.
This commit is contained in:
Jorge Rangel 2024-07-10 12:06:37 -05:00 коммит произвёл GitHub
Родитель 859f79268b
Коммит 4658a058e0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
18 изменённых файлов: 370 добавлений и 14 удалений

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

@ -200,9 +200,25 @@ namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
var result = new ParameterProvider("result", $"The {typeof(ClientResult):C} to deserialize the {Type:C} from.", typeof(ClientResult));
var modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static | MethodSignatureModifiers.Explicit | MethodSignatureModifiers.Operator;
// using PipelineResponse response = result.GetRawResponse();
var responseDeclaration = UsingDeclare("response", typeof(PipelineResponse), result.Invoke(nameof(ClientResult.GetRawResponse)), out var response);
// using JsonDocument document = JsonDocument.Parse(response.Content);
var document = UsingDeclare(
"document",
typeof(JsonDocument),
JsonDocumentSnippets.Parse(response.Property(nameof(PipelineResponse.Content)).As<BinaryData>()),
out var docVariable);
// return DeserializeT(doc.RootElement, ModelSerializationExtensions.WireOptions);
var deserialize = Return(_model.Deserialize(docVariable.As<JsonDocument>().RootElement(), ModelSerializationExtensionsSnippets.Wire));
var methodBody = new MethodBodyStatement[]
{
responseDeclaration,
document,
deserialize
};
return new MethodProvider(
new MethodSignature(Type.Name, null, modifiers, null, null, [result]),
Throw(New.NotImplementedException(Literal("Not implemented"))), //TODO https://github.com/microsoft/typespec/issues/3696
methodBody,
this);
}
@ -210,9 +226,11 @@ namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
var model = new ParameterProvider(Type.Name.ToVariableName(), $"The {Type:C} to serialize into {typeof(BinaryContent):C}", Type);
var modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static | MethodSignatureModifiers.Implicit | MethodSignatureModifiers.Operator;
// return BinaryContent.Create(model, ModelSerializationExtensions.WireOptions);
var binaryContentMethod = Static(typeof(BinaryContent)).Invoke(nameof(BinaryContent.Create), [model, ModelSerializationExtensionsSnippets.Wire]);
return new MethodProvider(
new MethodSignature(nameof(BinaryContent), null, modifiers, null, null, [model]),
Throw(New.NotImplementedException(Literal("Not implemented"))), //TODO https://github.com/microsoft/typespec/issues/3696
Return(binaryContentMethod),
this);
}

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

@ -0,0 +1,161 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ClientModel.Primitives;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Generator.CSharp.ClientModel.Tests
{
public class MockPipelineResponse : PipelineResponse
{
private int _status;
private string _reasonPhrase;
private Stream? _contentStream;
private BinaryData? _bufferedContent;
private readonly PipelineResponseHeaders _headers;
private bool _disposed;
public MockPipelineResponse(int status = 0, string reasonPhrase = "")
{
_status = status;
_reasonPhrase = reasonPhrase;
_headers = new MockResponseHeaders();
}
public override int Status => _status;
public void SetStatus(int value) => _status = value;
public override string ReasonPhrase => _reasonPhrase;
public void SetReasonPhrase(string value) => _reasonPhrase = value;
public void SetContent(byte[] content)
{
ContentStream = new MemoryStream(content, 0, content.Length, false, true);
}
public MockPipelineResponse SetContent(string content)
{
SetContent(Encoding.UTF8.GetBytes(content));
return this;
}
public override Stream? ContentStream
{
get => _contentStream;
set => _contentStream = value;
}
public override BinaryData Content
{
get
{
if (_contentStream is null)
{
return new BinaryData(Array.Empty<byte>());
}
if (ContentStream is not MemoryStream memoryContent)
{
throw new InvalidOperationException($"The response is not buffered.");
}
if (memoryContent.TryGetBuffer(out ArraySegment<byte> segment))
{
return new BinaryData(segment.AsMemory());
}
else
{
return new BinaryData(memoryContent.ToArray());
}
}
}
protected override PipelineResponseHeaders HeadersCore
=> _headers;
public sealed override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void Dispose(bool disposing)
{
if (disposing && !_disposed)
{
Stream? content = _contentStream;
if (content != null)
{
_contentStream = null;
content.Dispose();
}
_disposed = true;
}
}
public override BinaryData BufferContent(CancellationToken cancellationToken = default)
{
if (_bufferedContent is not null)
{
return _bufferedContent;
}
if (_contentStream is null)
{
_bufferedContent = new BinaryData(Array.Empty<byte>());
return _bufferedContent;
}
MemoryStream bufferStream = new();
_contentStream.CopyTo(bufferStream);
_contentStream.Dispose();
_contentStream = bufferStream;
// Less efficient FromStream method called here because it is a mock.
// For intended production implementation, see HttpClientTransportResponse.
_bufferedContent = BinaryData.FromStream(bufferStream);
return _bufferedContent;
}
public override async ValueTask<BinaryData> BufferContentAsync(CancellationToken cancellationToken = default)
{
if (_bufferedContent is not null)
{
return _bufferedContent;
}
if (_contentStream is null)
{
_bufferedContent = new BinaryData(Array.Empty<byte>());
return _bufferedContent;
}
MemoryStream bufferStream = new();
#if NETSTANDARD2_0 || NETFRAMEWORK
await _contentStream.CopyToAsync(bufferStream).ConfigureAwait(false);
_contentStream.Dispose();
#else
await _contentStream.CopyToAsync(bufferStream, cancellationToken).ConfigureAwait(false);
await _contentStream.DisposeAsync().ConfigureAwait(false);
#endif
_contentStream = bufferStream;
// Less efficient FromStream method called here because it is a mock.
// For intended production implementation, see HttpClientTransportResponse.
_bufferedContent = BinaryData.FromStream(bufferStream);
return _bufferedContent;
}
}
}

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

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
namespace Microsoft.Generator.CSharp.ClientModel.Tests
{
public class MockResponseHeaders : PipelineResponseHeaders
{
private readonly Dictionary<string, string> _headers;
public MockResponseHeaders()
{
_headers = new Dictionary<string, string>();
}
public override IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
throw new NotImplementedException();
}
public override bool TryGetValue(string name, out string? value)
{
return _headers.TryGetValue(name, out value);
}
public override bool TryGetValues(string name, out IEnumerable<string>? values)
{
throw new NotImplementedException();
}
}
}

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

@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.IO;
@ -40,6 +41,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
}
protected abstract void VerifyModel(T model, string format);
protected abstract void CompareModels(T model, T model2, string format);
protected abstract T ToModel(ClientResult result);
protected abstract BinaryContent ToBinaryContent(T model);
protected abstract string JsonPayload { get; }
protected abstract string WirePayload { get; }
@ -63,6 +66,10 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
public void RoundTripWithModelInterfaceNonGeneric(string format)
=> RoundTripTest(format, new ModelInterfaceAsObjectStrategy<T>());
[TestCase("W")]
public void RoundTripWithModelCast(string format)
=> RoundTripTest(format, new CastStrategy<T>(ToBinaryContent, ToModel));
protected void RoundTripTest(string format, RoundTripStrategy<T> strategy)
{
string serviceResponse = format == "J" ? JsonPayload : WirePayload;

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

@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.IO;
using System.Text;
@ -162,4 +163,44 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
return ((IJsonModel<object>)model).Create(ref reader, options);
}
}
public class CastStrategy<T> : RoundTripStrategy<T> where T : IPersistableModel<T>
{
public override bool IsExplicitJsonWrite => false;
public override bool IsExplicitJsonRead => false;
private readonly Func<T, BinaryContent> _toBinaryContent;
private readonly Func<ClientResult, T> _fromResult;
public CastStrategy(Func<T, BinaryContent> toRequestContent, Func<ClientResult, T> fromResult)
{
_toBinaryContent = toRequestContent;
_fromResult = fromResult;
}
public override BinaryData Write(T model, ModelReaderWriterOptions options)
{
BinaryContent content = _toBinaryContent(model);
content.TryComputeLength(out var length);
using var stream = new MemoryStream((int)length);
content.WriteTo(stream, default);
if (stream.Position > int.MaxValue)
{
return BinaryData.FromStream(stream);
}
else
{
return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position));
}
}
public override object Read(string payload, object model, ModelReaderWriterOptions options)
{
var responseWithBody = new MockPipelineResponse(200);
responseWithBody.SetContent(payload);
ClientResult result = ClientResult.FromResponse(responseWithBody);
return _fromResult(result);
}
}
}

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using NUnit.Framework;
using UnbrandedTypeSpec.Models;
@ -11,6 +12,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/Friend/Friend.json"));
protected override string WirePayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/Friend/FriendWireFormat.json"));
protected override Friend ToModel(ClientResult result) => (Friend)result;
protected override BinaryContent ToBinaryContent(Friend model) => model;
protected override void CompareModels(Friend model, Friend model2, string format)
{

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using System.Text.Json;
using NUnit.Framework;
@ -12,6 +13,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/ModelWithRequiredNullable/Model.json"));
protected override string WirePayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/ModelWithRequiredNullable/ModelWireFormat.json"));
protected override ModelWithRequiredNullableProperties ToModel(ClientResult result) => (ModelWithRequiredNullableProperties)result;
protected override BinaryContent ToBinaryContent(ModelWithRequiredNullableProperties model) => model;
protected override void CompareModels(ModelWithRequiredNullableProperties model, ModelWithRequiredNullableProperties model2, string format)
{

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using NUnit.Framework;
using UnbrandedTypeSpec.Models;
@ -11,6 +12,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/ProjectedModel/ProjectedModel.json"));
protected override string WirePayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/ProjectedModel/ProjectedModelWireFormat.json"));
protected override ProjectedModel ToModel(ClientResult result) => (ProjectedModel)result;
protected override BinaryContent ToBinaryContent(ProjectedModel model) => model;
protected override void CompareModels(ProjectedModel model, ProjectedModel model2, string format)
{

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using NUnit.Framework;
using UnbrandedTypeSpec.Models;
@ -11,6 +12,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/ReturnsAnonymousModelResp/Model.json"));
protected override string WirePayload => "{}";
protected override ReturnsAnonymousModelResponse ToModel(ClientResult result) => (ReturnsAnonymousModelResponse)result;
protected override BinaryContent ToBinaryContent(ReturnsAnonymousModelResponse model) => model;
protected override void CompareModels(ReturnsAnonymousModelResponse model, ReturnsAnonymousModelResponse model2, string format)
{

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using System.Text.Json;
using NUnit.Framework;
@ -12,6 +13,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/RoundTripModel/RoundTripModel.json"));
protected override string WirePayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/RoundTripModel/RoundTripModelWireFormat.json"));
protected override RoundTripModel ToModel(ClientResult result) => (RoundTripModel)result;
protected override BinaryContent ToBinaryContent(RoundTripModel model) => model;
protected override void CompareModels(RoundTripModel model, RoundTripModel model2, string format)
{

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.IO;
using System.Text.Json;
using NUnit.Framework;
@ -12,6 +13,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.ModelReaderWriterValidati
{
protected override string JsonPayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/Thing/Thing.json"));
protected override string WirePayload => File.ReadAllText(TestData.GetLocation("Unbranded-TypeSpec/TestData/Thing/ThingWireFormat.json"));
protected override Thing ToModel(ClientResult result) => (Thing)result;
protected override BinaryContent ToBinaryContent(Thing model) => model;
protected override void CompareModels(Thing model, Thing model2, string format)
{

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

@ -16,6 +16,7 @@ using Moq;
using Moq.Protected;
using NUnit.Framework;
using System.Text.Json;
using System.ClientModel;
using Microsoft.Generator.CSharp.ClientModel.Providers;
namespace Microsoft.Generator.CSharp.ClientModel.Tests.Providers.MrwSerializationTypeDefinitions
@ -591,5 +592,65 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.Providers.MrwSerializatio
var methodBody = deserializationMethod?.BodyStatements;
Assert.IsNotNull(methodBody);
}
[Test]
public void TestBuildImplicitToBinaryContent()
{
var inputModel = new InputModelType("mockInputModel", "mockNamespace", "public", null, null, InputModelTypeUsage.RoundTrip, Array.Empty<InputModelProperty>(), null, new List<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, false);
var mockModelTypeProvider = new ModelProvider(inputModel);
var jsonMrwSerializationTypeProvider = new MrwSerializationTypeDefinition(mockModelTypeProvider, inputModel);
var methods = jsonMrwSerializationTypeProvider.Methods;
Assert.IsTrue(methods.Count > 0);
var method = methods.FirstOrDefault(m => m.Signature.Name == nameof(BinaryContent));
Assert.IsNotNull(method);
var methodSignature = method?.Signature as MethodSignature;
Assert.IsNotNull(methodSignature);
var expectedModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static | MethodSignatureModifiers.Implicit | MethodSignatureModifiers.Operator;
Assert.AreEqual(nameof(BinaryContent), methodSignature?.Name);
Assert.AreEqual(expectedModifiers, methodSignature?.Modifiers);
var methodParameters = methodSignature?.Parameters;
Assert.AreEqual(1, methodParameters?.Count);
Assert.IsNull(methodSignature?.ReturnType);
var methodBody = method?.BodyStatements;
Assert.IsNotNull(methodBody);
}
[Test]
public void TestBuildExplicitFromClientResult()
{
var inputModel = new InputModelType("mockInputModel", "mockNamespace", "public", null, null, InputModelTypeUsage.RoundTrip, Array.Empty<InputModelProperty>(), null, new List<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, false);
var mockModelTypeProvider = new ModelProvider(inputModel);
var jsonMrwSerializationTypeProvider = new MrwSerializationTypeDefinition(mockModelTypeProvider, inputModel);
var methods = jsonMrwSerializationTypeProvider.Methods;
Assert.IsTrue(methods.Count > 0);
var method = methods.FirstOrDefault(m => m.Signature.Name == "MockInputModel");
Assert.IsNotNull(method);
var methodSignature = method?.Signature as MethodSignature;
Assert.IsNotNull(methodSignature);
var expectedModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static | MethodSignatureModifiers.Explicit | MethodSignatureModifiers.Operator;
Assert.AreEqual(inputModel.Name.FirstCharToUpperCase(), methodSignature?.Name);
Assert.AreEqual(expectedModifiers, methodSignature?.Modifiers);
var methodParameters = methodSignature?.Parameters;
Assert.AreEqual(1, methodParameters?.Count);
var clientResultParameter = methodParameters?[0];
Assert.AreEqual(new CSharpType(typeof(ClientResult)), clientResultParameter?.Type);
Assert.IsNull(methodSignature?.ReturnType);
var methodBody = method?.BodyStatements;
Assert.IsNotNull(methodBody);
}
}
}

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

@ -7,6 +7,7 @@ using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
using UnbrandedTypeSpec;
namespace UnbrandedTypeSpec.Models
{
@ -140,13 +141,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="friend"> The <see cref="Friend"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(Friend friend)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(friend, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="Friend"/> from. </param>
public static explicit operator Friend(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeFriend(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}

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

@ -7,6 +7,7 @@ using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
using UnbrandedTypeSpec;
namespace UnbrandedTypeSpec.Models
{
@ -194,13 +195,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="modelWithRequiredNullableProperties"> The <see cref="ModelWithRequiredNullableProperties"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(ModelWithRequiredNullableProperties modelWithRequiredNullableProperties)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(modelWithRequiredNullableProperties, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="ModelWithRequiredNullableProperties"/> from. </param>
public static explicit operator ModelWithRequiredNullableProperties(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeModelWithRequiredNullableProperties(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}

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

@ -7,6 +7,7 @@ using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
using UnbrandedTypeSpec;
namespace UnbrandedTypeSpec.Models
{
@ -140,13 +141,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="projectedModel"> The <see cref="ProjectedModel"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(ProjectedModel projectedModel)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(projectedModel, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="ProjectedModel"/> from. </param>
public static explicit operator ProjectedModel(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeProjectedModel(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}

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

@ -7,6 +7,7 @@ using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
using UnbrandedTypeSpec;
namespace UnbrandedTypeSpec.Models
{
@ -127,13 +128,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="returnsAnonymousModelResponse"> The <see cref="ReturnsAnonymousModelResponse"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(ReturnsAnonymousModelResponse returnsAnonymousModelResponse)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(returnsAnonymousModelResponse, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="ReturnsAnonymousModelResponse"/> from. </param>
public static explicit operator ReturnsAnonymousModelResponse(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeReturnsAnonymousModelResponse(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}

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

@ -677,13 +677,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="roundTripModel"> The <see cref="RoundTripModel"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(RoundTripModel roundTripModel)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(roundTripModel, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="RoundTripModel"/> from. </param>
public static explicit operator RoundTripModel(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeRoundTripModel(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}

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

@ -348,13 +348,15 @@ namespace UnbrandedTypeSpec.Models
/// <param name="thing"> The <see cref="Thing"/> to serialize into <see cref="BinaryContent"/>. </param>
public static implicit operator BinaryContent(Thing thing)
{
throw new NotImplementedException("Not implemented");
return BinaryContent.Create(thing, ModelSerializationExtensions.WireOptions);
}
/// <param name="result"> The <see cref="ClientResult"/> to deserialize the <see cref="Thing"/> from. </param>
public static explicit operator Thing(ClientResult result)
{
throw new NotImplementedException("Not implemented");
using PipelineResponse response = result.GetRawResponse();
using JsonDocument document = JsonDocument.Parse(response.Content);
return DeserializeThing(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}