From 483df5607c76aa9407bd4a69c41614b40c2a755a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:04:00 +0000 Subject: [PATCH 01/21] Initial plan From bd6ae2f483f453d85f0d01e9b07125cdf42c841a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:32:19 +0000 Subject: [PATCH 02/21] Update System.ClientModel to 1.5.1 and add ModelReaderWriterBuildableAttribute generation Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../MrwSerializationTypeDefinition.cs | 92 ++++++++++++++++++- .../generator/Packages.Data.props | 2 +- packages/http-client-csharp/global.json | 2 +- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs index a9bd55b66d6..ed7dac411d6 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs @@ -58,6 +58,83 @@ public class MrwSerializationTypeDefinition : TypeProvider private readonly bool _shouldOverrideMethods; private readonly Lazy _additionalProperties; + /// + /// Collects all types that implement IPersistableModel, including the current model and all properties + /// that are also IPersistableModel types, recursively without duplicates. + /// + private HashSet CollectBuildableTypes() + { + var buildableTypes = new HashSet(); + var visitedTypes = new HashSet(); + + // Start with the current model type + CollectBuildableTypesRecursive(_model.Type, buildableTypes, visitedTypes); + + return buildableTypes; + } + + /// + /// Recursively collects all types that implement IPersistableModel. + /// + private void CollectBuildableTypesRecursive(CSharpType type, HashSet buildableTypes, HashSet visitedTypes) + { + // Avoid infinite recursion by checking if we've already visited this type + if (visitedTypes.Contains(type) || type.IsFrameworkType) + { + return; + } + + visitedTypes.Add(type); + + // Check if this type implements IPersistableModel + if (ImplementsIPersistableModel(type)) + { + buildableTypes.Add(type); + + // Look for all properties of this type that are also IPersistableModel + var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders + .OfType() + .FirstOrDefault(m => m.Type.Equals(type)); + + if (modelProvider != null) + { + // Check all properties of this model + foreach (var property in modelProvider.Properties) + { + if (property.Type.IsCollection) + { + // For collections, check the element type + CollectBuildableTypesRecursive(property.Type.ElementType, buildableTypes, visitedTypes); + } + else + { + // For regular properties, check the property type + CollectBuildableTypesRecursive(property.Type, buildableTypes, visitedTypes); + } + } + } + } + } + + /// + /// Checks if a type implements IPersistableModel interface. + /// + private bool ImplementsIPersistableModel(CSharpType type) + { + // Check if the type is a model type (not a framework type) + if (type.IsFrameworkType) + { + return false; + } + + // All generated models implement IPersistableModel + var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders + .OfType() + .FirstOrDefault(m => m.Type.Equals(type)); + + return modelProvider != null; + } + public MrwSerializationTypeDefinition(InputModelType inputModel, ModelProvider modelProvider) { _model = modelProvider; @@ -93,15 +170,26 @@ public MrwSerializationTypeDefinition(InputModelType inputModel, ModelProvider m protected override IReadOnlyList BuildAttributes() { + var attributes = new List(); + + // Add existing PersistableModelProxyAttribute for abstract models if (_model.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Abstract)) { var unknownVariant = _model.DerivedModels.FirstOrDefault(m => m.IsUnknownDiscriminatorModel); if (unknownVariant != null) { - return [new AttributeStatement(typeof(PersistableModelProxyAttribute), TypeOf(unknownVariant.Type))]; + attributes.Add(new AttributeStatement(typeof(PersistableModelProxyAttribute), TypeOf(unknownVariant.Type))); } } - return []; + + // Add ModelReaderWriterBuildableAttribute for all IPersistableModel types + var buildableTypes = CollectBuildableTypes(); + foreach (var type in buildableTypes) + { + attributes.Add(new AttributeStatement(typeof(ModelReaderWriterBuildableAttribute), TypeOf(type))); + } + + return attributes; } protected override ConstructorProvider[] BuildConstructors() diff --git a/packages/http-client-csharp/generator/Packages.Data.props b/packages/http-client-csharp/generator/Packages.Data.props index 8dea2fdffaa..b55ea514ea6 100644 --- a/packages/http-client-csharp/generator/Packages.Data.props +++ b/packages/http-client-csharp/generator/Packages.Data.props @@ -14,7 +14,7 @@ - + diff --git a/packages/http-client-csharp/global.json b/packages/http-client-csharp/global.json index ef491491b99..42bb9956fc0 100644 --- a/packages/http-client-csharp/global.json +++ b/packages/http-client-csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.102", + "version": "8.0.117", "rollForward": "feature" } } From 92abab4aeeea9d5e56c4c43a6ef8a99ed44760b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:41:12 +0000 Subject: [PATCH 03/21] Complete implementation of ModelReaderWriterBuildableAttribute generation Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../ModelReaderWriterContextDefinition.cs | 103 ++++++++++++++++++ .../MrwSerializationTypeDefinition.cs | 92 +--------------- 2 files changed, 105 insertions(+), 90 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index 719f6aa5a0b..d86f5633be0 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -3,9 +3,13 @@ using System; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.IO; +using System.Linq; using Microsoft.TypeSpec.Generator.Primitives; using Microsoft.TypeSpec.Generator.Providers; +using Microsoft.TypeSpec.Generator.Statements; +using static Microsoft.TypeSpec.Generator.Snippets.Snippet; namespace Microsoft.TypeSpec.Generator.ClientModel.Providers { @@ -22,6 +26,105 @@ protected override TypeSignatureModifiers BuildDeclarationModifiers() protected override CSharpType[] BuildImplements() => [typeof(ModelReaderWriterContext)]; + protected override IReadOnlyList BuildAttributes() + { + var attributes = new List(); + + // Add ModelReaderWriterBuildableAttribute for all IPersistableModel types + var buildableTypes = CollectBuildableTypes(); + foreach (var type in buildableTypes) + { + attributes.Add(new AttributeStatement(typeof(ModelReaderWriterBuildableAttribute), TypeOf(type))); + } + + return attributes; + } + + /// + /// Collects all types that implement IPersistableModel, including all models and their properties + /// that are also IPersistableModel types, recursively without duplicates. + /// + private HashSet CollectBuildableTypes() + { + var buildableTypes = new HashSet(); + var visitedTypes = new HashSet(); + + // Get all model providers from the output library + var modelProviders = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders + .OfType() + .ToList(); + + // Process each model recursively + foreach (var modelProvider in modelProviders) + { + CollectBuildableTypesRecursive(modelProvider.Type, buildableTypes, visitedTypes); + } + + return buildableTypes; + } + + /// + /// Recursively collects all types that implement IPersistableModel. + /// + private void CollectBuildableTypesRecursive(CSharpType type, HashSet buildableTypes, HashSet visitedTypes) + { + // Avoid infinite recursion by checking if we've already visited this type + if (visitedTypes.Contains(type) || type.IsFrameworkType) + { + return; + } + + visitedTypes.Add(type); + + // Check if this type implements IPersistableModel + if (ImplementsIPersistableModel(type)) + { + buildableTypes.Add(type); + + // Look for all properties of this type that are also IPersistableModel + var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders + .OfType() + .FirstOrDefault(m => m.Type.Equals(type)); + + if (modelProvider != null) + { + // Check all properties of this model + foreach (var property in modelProvider.Properties) + { + if (property.Type.IsCollection) + { + // For collections, check the element type + CollectBuildableTypesRecursive(property.Type.ElementType, buildableTypes, visitedTypes); + } + else + { + // For regular properties, check the property type + CollectBuildableTypesRecursive(property.Type, buildableTypes, visitedTypes); + } + } + } + } + } + + /// + /// Checks if a type implements IPersistableModel interface. + /// + private bool ImplementsIPersistableModel(CSharpType type) + { + // Check if the type is a model type (not a framework type) + if (type.IsFrameworkType) + { + return false; + } + + // All generated models implement IPersistableModel + var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders + .OfType() + .FirstOrDefault(m => m.Type.Equals(type)); + + return modelProvider != null; + } + protected override XmlDocProvider BuildXmlDocs() { var summary = new Statements.XmlDocSummaryStatement( diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs index ed7dac411d6..a9bd55b66d6 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs @@ -58,83 +58,6 @@ public class MrwSerializationTypeDefinition : TypeProvider private readonly bool _shouldOverrideMethods; private readonly Lazy _additionalProperties; - /// - /// Collects all types that implement IPersistableModel, including the current model and all properties - /// that are also IPersistableModel types, recursively without duplicates. - /// - private HashSet CollectBuildableTypes() - { - var buildableTypes = new HashSet(); - var visitedTypes = new HashSet(); - - // Start with the current model type - CollectBuildableTypesRecursive(_model.Type, buildableTypes, visitedTypes); - - return buildableTypes; - } - - /// - /// Recursively collects all types that implement IPersistableModel. - /// - private void CollectBuildableTypesRecursive(CSharpType type, HashSet buildableTypes, HashSet visitedTypes) - { - // Avoid infinite recursion by checking if we've already visited this type - if (visitedTypes.Contains(type) || type.IsFrameworkType) - { - return; - } - - visitedTypes.Add(type); - - // Check if this type implements IPersistableModel - if (ImplementsIPersistableModel(type)) - { - buildableTypes.Add(type); - - // Look for all properties of this type that are also IPersistableModel - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - if (modelProvider != null) - { - // Check all properties of this model - foreach (var property in modelProvider.Properties) - { - if (property.Type.IsCollection) - { - // For collections, check the element type - CollectBuildableTypesRecursive(property.Type.ElementType, buildableTypes, visitedTypes); - } - else - { - // For regular properties, check the property type - CollectBuildableTypesRecursive(property.Type, buildableTypes, visitedTypes); - } - } - } - } - } - - /// - /// Checks if a type implements IPersistableModel interface. - /// - private bool ImplementsIPersistableModel(CSharpType type) - { - // Check if the type is a model type (not a framework type) - if (type.IsFrameworkType) - { - return false; - } - - // All generated models implement IPersistableModel - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - return modelProvider != null; - } - public MrwSerializationTypeDefinition(InputModelType inputModel, ModelProvider modelProvider) { _model = modelProvider; @@ -170,26 +93,15 @@ public MrwSerializationTypeDefinition(InputModelType inputModel, ModelProvider m protected override IReadOnlyList BuildAttributes() { - var attributes = new List(); - - // Add existing PersistableModelProxyAttribute for abstract models if (_model.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Abstract)) { var unknownVariant = _model.DerivedModels.FirstOrDefault(m => m.IsUnknownDiscriminatorModel); if (unknownVariant != null) { - attributes.Add(new AttributeStatement(typeof(PersistableModelProxyAttribute), TypeOf(unknownVariant.Type))); + return [new AttributeStatement(typeof(PersistableModelProxyAttribute), TypeOf(unknownVariant.Type))]; } } - - // Add ModelReaderWriterBuildableAttribute for all IPersistableModel types - var buildableTypes = CollectBuildableTypes(); - foreach (var type in buildableTypes) - { - attributes.Add(new AttributeStatement(typeof(ModelReaderWriterBuildableAttribute), TypeOf(type))); - } - - return attributes; + return []; } protected override ConstructorProvider[] BuildConstructors() From b8ae844314d833fb8ec1e4e9bfaa4ea843658a8f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 20:02:28 +0000 Subject: [PATCH 04/21] Revert global.json to original .NET SDK version 9.0.102 Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- packages/http-client-csharp/global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-csharp/global.json b/packages/http-client-csharp/global.json index 42bb9956fc0..ef491491b99 100644 --- a/packages/http-client-csharp/global.json +++ b/packages/http-client-csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.117", + "version": "9.0.102", "rollForward": "feature" } } From 8cb6c8abc3735f3fbb3323689a29c259f69efa73 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 20:39:41 +0000 Subject: [PATCH 05/21] Resolve merge conflicts and fix SDK version compatibility Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../src/Generated/SampleTypeSpecClient.cs | 1788 +++-------------- .../logging/Logging.Plugin/src/global.json | 2 +- .../Generated/Models/SampleTypeSpecContext.cs | 12 + packages/http-client-csharp/global.json | 2 +- 4 files changed, 323 insertions(+), 1481 deletions(-) diff --git a/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs b/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs index da04f3625b5..5377c494caa 100644 --- a/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs +++ b/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs @@ -72,24 +72,11 @@ public SampleTypeSpecClient(Uri endpoint, ApiKeyCredential keyCredential, Sample /// The response returned from the service. public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method SayHi."); - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method SayHi: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method SayHi."); - } + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -109,24 +96,11 @@ public virtual ClientResult SayHi(string headParameter, string queryParameter, s /// The response returned from the service. public virtual async Task SayHiAsync(string headParameter, string queryParameter, string optionalQuery, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method SayHiAsync."); - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method SayHiAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method SayHiAsync."); - } + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Return hi. @@ -138,24 +112,11 @@ public virtual async Task SayHiAsync(string headParameter, string /// Service returned a non-success status code. public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method SayHi."); - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method SayHi: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method SayHi."); - } + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// Return hi. @@ -167,24 +128,11 @@ public virtual ClientResult SayHi(string headParameter, string queryParam /// Service returned a non-success status code. public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method SayHiAsync."); - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method SayHiAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method SayHiAsync."); - } + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -204,25 +152,12 @@ public virtual async Task> SayHiAsync(string headParameter, /// The response returned from the service. public virtual ClientResult HelloAgain(string p2, string p1, BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method HelloAgain."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloAgain: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloAgain."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -242,25 +177,12 @@ public virtual ClientResult HelloAgain(string p2, string p1, BinaryContent conte /// The response returned from the service. public virtual async Task HelloAgainAsync(string p2, string p1, BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method HelloAgainAsync."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloAgainAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloAgainAsync."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Return hi again. @@ -272,25 +194,12 @@ public virtual async Task HelloAgainAsync(string p2, string p1, Bi /// Service returned a non-success status code. public virtual ClientResult HelloAgain(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloAgain."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(action, nameof(action)); - - ClientResult result = HelloAgain(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloAgain: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloAgain."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(action, nameof(action)); + + ClientResult result = HelloAgain(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); } /// Return hi again. @@ -302,25 +211,12 @@ public virtual ClientResult HelloAgain(string p2, string p1, Rou /// Service returned a non-success status code. public virtual async Task> HelloAgainAsync(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloAgainAsync."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(action, nameof(action)); - - ClientResult result = await HelloAgainAsync(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloAgainAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloAgainAsync."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(action, nameof(action)); + + ClientResult result = await HelloAgainAsync(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); } /// @@ -340,25 +236,12 @@ public virtual async Task> HelloAgainAsync(string p /// The response returned from the service. public virtual ClientResult NoContentType(string p2, string p1, BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method NoContentType."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method NoContentType: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method NoContentType."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -378,25 +261,12 @@ public virtual ClientResult NoContentType(string p2, string p1, BinaryContent co /// The response returned from the service. public virtual async Task NoContentTypeAsync(string p2, string p1, BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method NoContentTypeAsync."); - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method NoContentTypeAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method NoContentTypeAsync."); - } + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// @@ -412,21 +282,8 @@ public virtual async Task NoContentTypeAsync(string p2, string p1, /// The response returned from the service. public virtual ClientResult HelloDemo2(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HelloDemo2."); - using PipelineMessage message = CreateHelloDemo2Request(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloDemo2: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloDemo2."); - } + using PipelineMessage message = CreateHelloDemo2Request(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -442,21 +299,8 @@ public virtual ClientResult HelloDemo2(RequestOptions options) /// The response returned from the service. public virtual async Task HelloDemo2Async(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HelloDemo2Async."); - using PipelineMessage message = CreateHelloDemo2Request(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloDemo2Async: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloDemo2Async."); - } + using PipelineMessage message = CreateHelloDemo2Request(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Return hi in demo2. @@ -464,21 +308,8 @@ public virtual async Task HelloDemo2Async(RequestOptions options) /// Service returned a non-success status code. public virtual ClientResult HelloDemo2(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloDemo2."); - ClientResult result = HelloDemo2(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloDemo2: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloDemo2."); - } + ClientResult result = HelloDemo2(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// Return hi in demo2. @@ -486,21 +317,8 @@ public virtual ClientResult HelloDemo2(CancellationToken cancellationToke /// Service returned a non-success status code. public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloDemo2Async."); - ClientResult result = await HelloDemo2Async(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloDemo2Async: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloDemo2Async."); - } + ClientResult result = await HelloDemo2Async(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -518,23 +336,10 @@ public virtual async Task> HelloDemo2Async(CancellationToken /// The response returned from the service. public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method CreateLiteral."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateCreateLiteralRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method CreateLiteral: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method CreateLiteral."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateLiteralRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -552,23 +357,10 @@ public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task CreateLiteralAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method CreateLiteralAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateCreateLiteralRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method CreateLiteralAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method CreateLiteralAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateLiteralRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Create with literal value. @@ -578,23 +370,10 @@ public virtual async Task CreateLiteralAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult CreateLiteral(Thing body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method CreateLiteral."); - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = CreateLiteral(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method CreateLiteral: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method CreateLiteral."); - } + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = CreateLiteral(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// Create with literal value. @@ -604,23 +383,10 @@ public virtual ClientResult CreateLiteral(Thing body, CancellationToken c /// Service returned a non-success status code. public virtual async Task> CreateLiteralAsync(Thing body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method CreateLiteralAsync."); - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = await CreateLiteralAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method CreateLiteralAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method CreateLiteralAsync."); - } + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = await CreateLiteralAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -636,21 +402,8 @@ public virtual async Task> CreateLiteralAsync(Thing body, Ca /// The response returned from the service. public virtual ClientResult HelloLiteral(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HelloLiteral."); - using PipelineMessage message = CreateHelloLiteralRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloLiteral: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloLiteral."); - } + using PipelineMessage message = CreateHelloLiteralRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -666,21 +419,8 @@ public virtual ClientResult HelloLiteral(RequestOptions options) /// The response returned from the service. public virtual async Task HelloLiteralAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HelloLiteralAsync."); - using PipelineMessage message = CreateHelloLiteralRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloLiteralAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloLiteralAsync."); - } + using PipelineMessage message = CreateHelloLiteralRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Send literal parameters. @@ -688,21 +428,8 @@ public virtual async Task HelloLiteralAsync(RequestOptions options /// Service returned a non-success status code. public virtual ClientResult HelloLiteral(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloLiteral."); - ClientResult result = HelloLiteral(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloLiteral: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloLiteral."); - } + ClientResult result = HelloLiteral(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// Send literal parameters. @@ -710,21 +437,8 @@ public virtual ClientResult HelloLiteral(CancellationToken cancellationTo /// Service returned a non-success status code. public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HelloLiteralAsync."); - ClientResult result = await HelloLiteralAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HelloLiteralAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HelloLiteralAsync."); - } + ClientResult result = await HelloLiteralAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -741,21 +455,8 @@ public virtual async Task> HelloLiteralAsync(CancellationTok /// The response returned from the service. public virtual ClientResult TopAction(DateTimeOffset action, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method TopAction."); - using PipelineMessage message = CreateTopActionRequest(action, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopAction: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopAction."); - } + using PipelineMessage message = CreateTopActionRequest(action, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -772,21 +473,8 @@ public virtual ClientResult TopAction(DateTimeOffset action, RequestOptions opti /// The response returned from the service. public virtual async Task TopActionAsync(DateTimeOffset action, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method TopActionAsync."); - using PipelineMessage message = CreateTopActionRequest(action, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopActionAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopActionAsync."); - } + using PipelineMessage message = CreateTopActionRequest(action, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// top level method. @@ -795,21 +483,8 @@ public virtual async Task TopActionAsync(DateTimeOffset action, Re /// Service returned a non-success status code. public virtual ClientResult TopAction(DateTimeOffset action, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method TopAction."); - ClientResult result = TopAction(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopAction: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopAction."); - } + ClientResult result = TopAction(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// top level method. @@ -818,21 +493,8 @@ public virtual ClientResult TopAction(DateTimeOffset action, Cancellation /// Service returned a non-success status code. public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method TopActionAsync."); - ClientResult result = await TopActionAsync(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopActionAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopActionAsync."); - } + ClientResult result = await TopActionAsync(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -848,21 +510,8 @@ public virtual async Task> TopActionAsync(DateTimeOffset act /// The response returned from the service. public virtual ClientResult TopAction2(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method TopAction2."); - using PipelineMessage message = CreateTopAction2Request(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopAction2: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopAction2."); - } + using PipelineMessage message = CreateTopAction2Request(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -878,21 +527,8 @@ public virtual ClientResult TopAction2(RequestOptions options) /// The response returned from the service. public virtual async Task TopAction2Async(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method TopAction2Async."); - using PipelineMessage message = CreateTopAction2Request(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method TopAction2Async: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method TopAction2Async."); - } + using PipelineMessage message = CreateTopAction2Request(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// @@ -910,23 +546,10 @@ public virtual async Task TopAction2Async(RequestOptions options) /// The response returned from the service. public virtual ClientResult PatchAction(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method PatchAction."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreatePatchActionRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method PatchAction: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method PatchAction."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePatchActionRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -944,23 +567,10 @@ public virtual ClientResult PatchAction(BinaryContent content, RequestOptions op /// The response returned from the service. public virtual async Task PatchActionAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method PatchActionAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreatePatchActionRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method PatchActionAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method PatchActionAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePatchActionRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// @@ -978,23 +588,10 @@ public virtual async Task PatchActionAsync(BinaryContent content, /// The response returned from the service. public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method AnonymousBody."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateAnonymousBodyRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AnonymousBody: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AnonymousBody."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAnonymousBodyRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1012,23 +609,10 @@ public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task AnonymousBodyAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method AnonymousBodyAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateAnonymousBodyRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AnonymousBodyAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AnonymousBodyAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAnonymousBodyRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// body parameter without body decorator. @@ -1052,43 +636,30 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult AnonymousBody(string name, BinaryData requiredUnion, string requiredLiteralString, string requiredNullableString, int requiredLiteralInt, float requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, string optionalLiteralString = default, int? optionalLiteralInt = default, float? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method AnonymousBody."); - Argument.AssertNotNull(name, nameof(name)); - Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); - Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); - Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); - - Thing spreadModel = new Thing( - name, - requiredUnion, - requiredLiteralString, - requiredNullableString, - optionalNullableString, - requiredLiteralInt, - requiredLiteralFloat, - requiredLiteralBool, - optionalLiteralString, - optionalLiteralInt, - optionalLiteralFloat, - optionalLiteralBool, - requiredBadDescription, - optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), - requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), - null); - ClientResult result = AnonymousBody(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AnonymousBody: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AnonymousBody."); - } + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); + Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); + Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); + + Thing spreadModel = new Thing( + name, + requiredUnion, + requiredLiteralString, + requiredNullableString, + optionalNullableString, + requiredLiteralInt, + requiredLiteralFloat, + requiredLiteralBool, + optionalLiteralString, + optionalLiteralInt, + optionalLiteralFloat, + optionalLiteralBool, + requiredBadDescription, + optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), + requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), + null); + ClientResult result = AnonymousBody(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// body parameter without body decorator. @@ -1112,43 +683,30 @@ public virtual ClientResult AnonymousBody(string name, BinaryData require /// Service returned a non-success status code. public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, string requiredLiteralString, string requiredNullableString, int requiredLiteralInt, float requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, string optionalLiteralString = default, int? optionalLiteralInt = default, float? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method AnonymousBodyAsync."); - Argument.AssertNotNull(name, nameof(name)); - Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); - Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); - Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); - - Thing spreadModel = new Thing( - name, - requiredUnion, - requiredLiteralString, - requiredNullableString, - optionalNullableString, - requiredLiteralInt, - requiredLiteralFloat, - requiredLiteralBool, - optionalLiteralString, - optionalLiteralInt, - optionalLiteralFloat, - optionalLiteralBool, - requiredBadDescription, - optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), - requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), - null); - ClientResult result = await AnonymousBodyAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AnonymousBodyAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AnonymousBodyAsync."); - } + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); + Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); + Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); + + Thing spreadModel = new Thing( + name, + requiredUnion, + requiredLiteralString, + requiredNullableString, + optionalNullableString, + requiredLiteralInt, + requiredLiteralFloat, + requiredLiteralBool, + optionalLiteralString, + optionalLiteralInt, + optionalLiteralFloat, + optionalLiteralBool, + requiredBadDescription, + optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), + requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), + null); + ClientResult result = await AnonymousBodyAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -1166,23 +724,10 @@ public virtual async Task> AnonymousBodyAsync(string name, B /// The response returned from the service. public virtual ClientResult FriendlyModel(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method FriendlyModel."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateFriendlyModelRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method FriendlyModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method FriendlyModel."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateFriendlyModelRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1200,23 +745,10 @@ public virtual ClientResult FriendlyModel(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task FriendlyModelAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method FriendlyModelAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateFriendlyModelRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method FriendlyModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method FriendlyModelAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateFriendlyModelRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Model can have its friendly name. @@ -1226,24 +758,11 @@ public virtual async Task FriendlyModelAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult FriendlyModel(string name, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method FriendlyModel."); - Argument.AssertNotNull(name, nameof(name)); - - Friend spreadModel = new Friend(name, null); - ClientResult result = FriendlyModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Friend)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method FriendlyModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method FriendlyModel."); - } + Argument.AssertNotNull(name, nameof(name)); + + Friend spreadModel = new Friend(name, null); + ClientResult result = FriendlyModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Friend)result, result.GetRawResponse()); } /// Model can have its friendly name. @@ -1253,24 +772,11 @@ public virtual ClientResult FriendlyModel(string name, CancellationToken /// Service returned a non-success status code. public virtual async Task> FriendlyModelAsync(string name, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method FriendlyModelAsync."); - Argument.AssertNotNull(name, nameof(name)); - - Friend spreadModel = new Friend(name, null); - ClientResult result = await FriendlyModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Friend)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method FriendlyModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method FriendlyModelAsync."); - } + Argument.AssertNotNull(name, nameof(name)); + + Friend spreadModel = new Friend(name, null); + ClientResult result = await FriendlyModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Friend)result, result.GetRawResponse()); } /// @@ -1286,21 +792,8 @@ public virtual async Task> FriendlyModelAsync(string name, /// The response returned from the service. public virtual ClientResult AddTimeHeader(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method AddTimeHeader."); - using PipelineMessage message = CreateAddTimeHeaderRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AddTimeHeader: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AddTimeHeader."); - } + using PipelineMessage message = CreateAddTimeHeaderRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1316,21 +809,8 @@ public virtual ClientResult AddTimeHeader(RequestOptions options) /// The response returned from the service. public virtual async Task AddTimeHeaderAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method AddTimeHeaderAsync."); - using PipelineMessage message = CreateAddTimeHeaderRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AddTimeHeaderAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AddTimeHeaderAsync."); - } + using PipelineMessage message = CreateAddTimeHeaderRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// addTimeHeader. @@ -1338,20 +818,7 @@ public virtual async Task AddTimeHeaderAsync(RequestOptions option /// Service returned a non-success status code. public virtual ClientResult AddTimeHeader(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method AddTimeHeader."); - return AddTimeHeader(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AddTimeHeader: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AddTimeHeader."); - } + return AddTimeHeader(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// addTimeHeader. @@ -1359,20 +826,7 @@ public virtual ClientResult AddTimeHeader(CancellationToken cancellationToken = /// Service returned a non-success status code. public virtual async Task AddTimeHeaderAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method AddTimeHeaderAsync."); - return await AddTimeHeaderAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method AddTimeHeaderAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method AddTimeHeaderAsync."); - } + return await AddTimeHeaderAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); } /// @@ -1390,23 +844,10 @@ public virtual async Task AddTimeHeaderAsync(CancellationToken can /// The response returned from the service. public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method ProjectedNameModel."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateProjectedNameModelRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ProjectedNameModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ProjectedNameModel."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateProjectedNameModelRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1424,23 +865,10 @@ public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOpt /// The response returned from the service. public virtual async Task ProjectedNameModelAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method ProjectedNameModelAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateProjectedNameModelRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ProjectedNameModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ProjectedNameModelAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateProjectedNameModelRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Model can have its projected name. @@ -1450,24 +878,11 @@ public virtual async Task ProjectedNameModelAsync(BinaryContent co /// Service returned a non-success status code. public virtual ClientResult ProjectedNameModel(string name, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ProjectedNameModel."); - Argument.AssertNotNull(name, nameof(name)); - - RenamedModel spreadModel = new RenamedModel(name, null); - ClientResult result = ProjectedNameModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ProjectedNameModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ProjectedNameModel."); - } + Argument.AssertNotNull(name, nameof(name)); + + RenamedModel spreadModel = new RenamedModel(name, null); + ClientResult result = ProjectedNameModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); } /// Model can have its projected name. @@ -1477,24 +892,11 @@ public virtual ClientResult ProjectedNameModel(string name, Cancel /// Service returned a non-success status code. public virtual async Task> ProjectedNameModelAsync(string name, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ProjectedNameModelAsync."); - Argument.AssertNotNull(name, nameof(name)); - - RenamedModel spreadModel = new RenamedModel(name, null); - ClientResult result = await ProjectedNameModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ProjectedNameModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ProjectedNameModelAsync."); - } + Argument.AssertNotNull(name, nameof(name)); + + RenamedModel spreadModel = new RenamedModel(name, null); + ClientResult result = await ProjectedNameModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); } /// @@ -1510,21 +912,8 @@ public virtual async Task> ProjectedNameModelAsync(st /// The response returned from the service. public virtual ClientResult ReturnsAnonymousModel(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ReturnsAnonymousModel."); - using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ReturnsAnonymousModel."); - } + using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1540,21 +929,8 @@ public virtual ClientResult ReturnsAnonymousModel(RequestOptions options) /// The response returned from the service. public virtual async Task ReturnsAnonymousModelAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ReturnsAnonymousModelAsync."); - using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ReturnsAnonymousModelAsync."); - } + using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// return anonymous model. @@ -1562,21 +938,8 @@ public virtual async Task ReturnsAnonymousModelAsync(RequestOption /// Service returned a non-success status code. public virtual ClientResult ReturnsAnonymousModel(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ReturnsAnonymousModel."); - ClientResult result = ReturnsAnonymousModel(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModel: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ReturnsAnonymousModel."); - } + ClientResult result = ReturnsAnonymousModel(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); } /// return anonymous model. @@ -1584,21 +947,8 @@ public virtual ClientResult ReturnsAnonymousModel /// Service returned a non-success status code. public virtual async Task> ReturnsAnonymousModelAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ReturnsAnonymousModelAsync."); - ClientResult result = await ReturnsAnonymousModelAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModelAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ReturnsAnonymousModelAsync."); - } + ClientResult result = await ReturnsAnonymousModelAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); } /// @@ -1616,23 +966,10 @@ public virtual async Task> ReturnsAn /// The response returned from the service. public virtual ClientResult GetUnknownValue(string accept, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method GetUnknownValue."); - Argument.AssertNotNull(accept, nameof(accept)); - - using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method GetUnknownValue: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method GetUnknownValue."); - } + Argument.AssertNotNull(accept, nameof(accept)); + + using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1650,23 +987,10 @@ public virtual ClientResult GetUnknownValue(string accept, RequestOptions option /// The response returned from the service. public virtual async Task GetUnknownValueAsync(string accept, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method GetUnknownValueAsync."); - Argument.AssertNotNull(accept, nameof(accept)); - - using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method GetUnknownValueAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method GetUnknownValueAsync."); - } + Argument.AssertNotNull(accept, nameof(accept)); + + using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// get extensible enum. @@ -1676,23 +1000,10 @@ public virtual async Task GetUnknownValueAsync(string accept, Requ /// Service returned a non-success status code. public virtual ClientResult GetUnknownValue(string accept, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method GetUnknownValue."); - Argument.AssertNotNull(accept, nameof(accept)); - - ClientResult result = GetUnknownValue(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method GetUnknownValue: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method GetUnknownValue."); - } + Argument.AssertNotNull(accept, nameof(accept)); + + ClientResult result = GetUnknownValue(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); } /// get extensible enum. @@ -1702,23 +1013,10 @@ public virtual ClientResult GetUnknownValue(string accept, CancellationT /// Service returned a non-success status code. public virtual async Task> GetUnknownValueAsync(string accept, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method GetUnknownValueAsync."); - Argument.AssertNotNull(accept, nameof(accept)); - - ClientResult result = await GetUnknownValueAsync(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method GetUnknownValueAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method GetUnknownValueAsync."); - } + Argument.AssertNotNull(accept, nameof(accept)); + + ClientResult result = await GetUnknownValueAsync(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); } /// @@ -1736,23 +1034,10 @@ public virtual async Task> GetUnknownValueAsync(string acce /// The response returned from the service. public virtual ClientResult InternalProtocol(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method InternalProtocol."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateInternalProtocolRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method InternalProtocol: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method InternalProtocol."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateInternalProtocolRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1770,23 +1055,10 @@ public virtual ClientResult InternalProtocol(BinaryContent content, RequestOptio /// The response returned from the service. public virtual async Task InternalProtocolAsync(BinaryContent content, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method InternalProtocolAsync."); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateInternalProtocolRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method InternalProtocolAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method InternalProtocolAsync."); - } + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateInternalProtocolRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// When set protocol false and convenient true, then the protocol method should be internal. @@ -1796,23 +1068,10 @@ public virtual async Task InternalProtocolAsync(BinaryContent cont /// Service returned a non-success status code. public virtual ClientResult InternalProtocol(Thing body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method InternalProtocol."); - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = InternalProtocol(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method InternalProtocol: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method InternalProtocol."); - } + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = InternalProtocol(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// When set protocol false and convenient true, then the protocol method should be internal. @@ -1822,23 +1081,10 @@ public virtual ClientResult InternalProtocol(Thing body, CancellationToke /// Service returned a non-success status code. public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method InternalProtocolAsync."); - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = await InternalProtocolAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method InternalProtocolAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method InternalProtocolAsync."); - } + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = await InternalProtocolAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); } /// @@ -1854,21 +1100,8 @@ public virtual async Task> InternalProtocolAsync(Thing body, /// The response returned from the service. public virtual ClientResult StillConvenient(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method StillConvenient."); - using PipelineMessage message = CreateStillConvenientRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method StillConvenient: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method StillConvenient."); - } + using PipelineMessage message = CreateStillConvenientRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1884,21 +1117,8 @@ public virtual ClientResult StillConvenient(RequestOptions options) /// The response returned from the service. public virtual async Task StillConvenientAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method StillConvenientAsync."); - using PipelineMessage message = CreateStillConvenientRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method StillConvenientAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method StillConvenientAsync."); - } + using PipelineMessage message = CreateStillConvenientRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. @@ -1906,20 +1126,7 @@ public virtual async Task StillConvenientAsync(RequestOptions opti /// Service returned a non-success status code. public virtual ClientResult StillConvenient(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method StillConvenient."); - return StillConvenient(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method StillConvenient: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method StillConvenient."); - } + return StillConvenient(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. @@ -1927,20 +1134,7 @@ public virtual ClientResult StillConvenient(CancellationToken cancellationToken /// Service returned a non-success status code. public virtual async Task StillConvenientAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method StillConvenientAsync."); - return await StillConvenientAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method StillConvenientAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method StillConvenientAsync."); - } + return await StillConvenientAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); } /// @@ -1958,23 +1152,10 @@ public virtual async Task StillConvenientAsync(CancellationToken c /// The response returned from the service. public virtual ClientResult HeadAsBoolean(string id, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HeadAsBoolean."); - Argument.AssertNotNull(id, nameof(id)); - - using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HeadAsBoolean: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HeadAsBoolean."); - } + Argument.AssertNotNull(id, nameof(id)); + + using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -1992,23 +1173,10 @@ public virtual ClientResult HeadAsBoolean(string id, RequestOptions options) /// The response returned from the service. public virtual async Task HeadAsBooleanAsync(string id, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method HeadAsBooleanAsync."); - Argument.AssertNotNull(id, nameof(id)); - - using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HeadAsBooleanAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HeadAsBooleanAsync."); - } + Argument.AssertNotNull(id, nameof(id)); + + using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// head as boolean. @@ -2018,22 +1186,9 @@ public virtual async Task HeadAsBooleanAsync(string id, RequestOpt /// Service returned a non-success status code. public virtual ClientResult HeadAsBoolean(string id, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HeadAsBoolean."); - Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(id, nameof(id)); - return HeadAsBoolean(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HeadAsBoolean: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HeadAsBoolean."); - } + return HeadAsBoolean(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// head as boolean. @@ -2043,22 +1198,9 @@ public virtual ClientResult HeadAsBoolean(string id, CancellationToken cancellat /// Service returned a non-success status code. public virtual async Task HeadAsBooleanAsync(string id, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method HeadAsBooleanAsync."); - Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(id, nameof(id)); - return await HeadAsBooleanAsync(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method HeadAsBooleanAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method HeadAsBooleanAsync."); - } + return await HeadAsBooleanAsync(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); } /// @@ -2076,23 +1218,10 @@ public virtual async Task HeadAsBooleanAsync(string id, Cancellati /// The response returned from the service. public virtual ClientResult WithApiVersion(string p1, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method WithApiVersion."); - Argument.AssertNotNull(p1, nameof(p1)); - - using PipelineMessage message = CreateWithApiVersionRequest(p1, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method WithApiVersion: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method WithApiVersion."); - } + Argument.AssertNotNull(p1, nameof(p1)); + + using PipelineMessage message = CreateWithApiVersionRequest(p1, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -2110,23 +1239,10 @@ public virtual ClientResult WithApiVersion(string p1, RequestOptions options) /// The response returned from the service. public virtual async Task WithApiVersionAsync(string p1, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method WithApiVersionAsync."); - Argument.AssertNotNull(p1, nameof(p1)); - - using PipelineMessage message = CreateWithApiVersionRequest(p1, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method WithApiVersionAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method WithApiVersionAsync."); - } + Argument.AssertNotNull(p1, nameof(p1)); + + using PipelineMessage message = CreateWithApiVersionRequest(p1, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// Return hi again. @@ -2136,22 +1252,9 @@ public virtual async Task WithApiVersionAsync(string p1, RequestOp /// Service returned a non-success status code. public virtual ClientResult WithApiVersion(string p1, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method WithApiVersion."); - Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(p1, nameof(p1)); - return WithApiVersion(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method WithApiVersion: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method WithApiVersion."); - } + return WithApiVersion(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// Return hi again. @@ -2161,22 +1264,9 @@ public virtual ClientResult WithApiVersion(string p1, CancellationToken cancella /// Service returned a non-success status code. public virtual async Task WithApiVersionAsync(string p1, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method WithApiVersionAsync."); - Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(p1, nameof(p1)); - return await WithApiVersionAsync(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method WithApiVersionAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method WithApiVersionAsync."); - } + return await WithApiVersionAsync(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); } /// @@ -2192,20 +1282,7 @@ public virtual async Task WithApiVersionAsync(string p1, Cancellat /// The response returned from the service. public virtual CollectionResult ListWithNextLink(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithNextLink."); - return new SampleTypeSpecClientListWithNextLinkCollectionResult(this, null, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithNextLink: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithNextLink."); - } + return new SampleTypeSpecClientListWithNextLinkCollectionResult(this, null, options); } /// @@ -2221,20 +1298,7 @@ public virtual CollectionResult ListWithNextLink(RequestOptions options) /// The response returned from the service. public virtual AsyncCollectionResult ListWithNextLinkAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithNextLinkAsync."); - return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResult(this, null, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithNextLinkAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithNextLinkAsync."); - } + return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResult(this, null, options); } /// List things with nextlink. @@ -2242,20 +1306,7 @@ public virtual AsyncCollectionResult ListWithNextLinkAsync(RequestOptions option /// Service returned a non-success status code. public virtual CollectionResult ListWithNextLink(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithNextLink."); - return new SampleTypeSpecClientListWithNextLinkCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithNextLink: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithNextLink."); - } + return new SampleTypeSpecClientListWithNextLinkCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// List things with nextlink. @@ -2263,20 +1314,7 @@ public virtual CollectionResult ListWithNextLink(CancellationToken cancel /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithNextLinkAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithNextLinkAsync."); - return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithNextLinkAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithNextLinkAsync."); - } + return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// @@ -2293,20 +1331,7 @@ public virtual AsyncCollectionResult ListWithNextLinkAsync(CancellationTo /// The response returned from the service. public virtual CollectionResult ListWithContinuationToken(string token, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationToken."); - return new SampleTypeSpecClientListWithContinuationTokenCollectionResult(this, token, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationToken: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationToken."); - } + return new SampleTypeSpecClientListWithContinuationTokenCollectionResult(this, token, options); } /// @@ -2323,20 +1348,7 @@ public virtual CollectionResult ListWithContinuationToken(string token, RequestO /// The response returned from the service. public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenAsync."); - return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResult(this, token, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenAsync."); - } + return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResult(this, token, options); } /// List things with continuation token. @@ -2345,20 +1357,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token /// Service returned a non-success status code. public virtual CollectionResult ListWithContinuationToken(string token = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationToken."); - return new SampleTypeSpecClientListWithContinuationTokenCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationToken: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationToken."); - } + return new SampleTypeSpecClientListWithContinuationTokenCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// List things with continuation token. @@ -2367,20 +1366,7 @@ public virtual CollectionResult ListWithContinuationToken(string token = /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenAsync."); - return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenAsync."); - } + return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// @@ -2397,20 +1383,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenAsync(strin /// The response returned from the service. public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string token, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponse."); - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResult(this, token, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponse: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponse."); - } + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResult(this, token, options); } /// @@ -2427,20 +1400,7 @@ public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string t /// The response returned from the service. public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsync(string token, RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponseAsync."); - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResult(this, token, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponseAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponseAsync."); - } + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResult(this, token, options); } /// List things with continuation token header response. @@ -2449,20 +1409,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsyn /// Service returned a non-success status code. public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string token = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponse."); - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponse: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponse."); - } + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// List things with continuation token header response. @@ -2471,20 +1418,7 @@ public virtual CollectionResult ListWithContinuationTokenHeaderResponse(s /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsync(string token = default, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponseAsync."); - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponseAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponseAsync."); - } + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// @@ -2500,20 +1434,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenHeaderRespo /// The response returned from the service. public virtual CollectionResult ListWithPaging(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithPaging."); - return new SampleTypeSpecClientListWithPagingCollectionResult(this, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithPaging: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithPaging."); - } + return new SampleTypeSpecClientListWithPagingCollectionResult(this, options); } /// @@ -2529,20 +1450,7 @@ public virtual CollectionResult ListWithPaging(RequestOptions options) /// The response returned from the service. public virtual AsyncCollectionResult ListWithPagingAsync(RequestOptions options) { - try - { - System.Console.WriteLine("Entering method ListWithPagingAsync."); - return new SampleTypeSpecClientListWithPagingAsyncCollectionResult(this, options); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithPagingAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithPagingAsync."); - } + return new SampleTypeSpecClientListWithPagingAsyncCollectionResult(this, options); } /// List things with paging. @@ -2550,20 +1458,7 @@ public virtual AsyncCollectionResult ListWithPagingAsync(RequestOptions options) /// Service returned a non-success status code. public virtual CollectionResult ListWithPaging(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithPaging."); - return new SampleTypeSpecClientListWithPagingCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithPaging: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithPaging."); - } + return new SampleTypeSpecClientListWithPagingCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// List things with paging. @@ -2571,20 +1466,7 @@ public virtual CollectionResult ListWithPaging(CancellationToken cancella /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithPagingAsync(CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method ListWithPagingAsync."); - return new SampleTypeSpecClientListWithPagingAsyncCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method ListWithPagingAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method ListWithPagingAsync."); - } + return new SampleTypeSpecClientListWithPagingAsyncCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// @@ -2606,25 +1488,12 @@ public virtual AsyncCollectionResult ListWithPagingAsync(CancellationToke /// The response returned from the service. public virtual ClientResult EmbeddedParameters(string requiredHeader, string requiredQuery, BinaryContent content, string optionalHeader = default, string optionalQuery = default, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method EmbeddedParameters."); - Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); - Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method EmbeddedParameters: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method EmbeddedParameters."); - } + Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); + Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// @@ -2646,25 +1515,12 @@ public virtual ClientResult EmbeddedParameters(string requiredHeader, string req /// The response returned from the service. public virtual async Task EmbeddedParametersAsync(string requiredHeader, string requiredQuery, BinaryContent content, string optionalHeader = default, string optionalQuery = default, RequestOptions options = null) { - try - { - System.Console.WriteLine("Entering method EmbeddedParametersAsync."); - Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); - Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method EmbeddedParametersAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method EmbeddedParametersAsync."); - } + Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); + Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// An operation with embedded parameters within the body. @@ -2674,22 +1530,9 @@ public virtual async Task EmbeddedParametersAsync(string requiredH /// Service returned a non-success status code. public virtual ClientResult EmbeddedParameters(ModelWithEmbeddedNonBodyParameters body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method EmbeddedParameters."); - Argument.AssertNotNull(body, nameof(body)); + Argument.AssertNotNull(body, nameof(body)); - return EmbeddedParameters(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method EmbeddedParameters: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method EmbeddedParameters."); - } + return EmbeddedParameters(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); } /// An operation with embedded parameters within the body. @@ -2699,22 +1542,9 @@ public virtual ClientResult EmbeddedParameters(ModelWithEmbeddedNonBodyParameter /// Service returned a non-success status code. public virtual async Task EmbeddedParametersAsync(ModelWithEmbeddedNonBodyParameters body, CancellationToken cancellationToken = default) { - try - { - System.Console.WriteLine("Entering method EmbeddedParametersAsync."); - Argument.AssertNotNull(body, nameof(body)); - - return await EmbeddedParametersAsync(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - } - catch (Exception ex) - { - System.Console.WriteLine($"An exception was thrown in method EmbeddedParametersAsync: {ex}"); - throw; - } - finally - { - System.Console.WriteLine("Exiting method EmbeddedParametersAsync."); - } + Argument.AssertNotNull(body, nameof(body)); + + return await EmbeddedParametersAsync(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); } } } diff --git a/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json b/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json index ef491491b99..42bb9956fc0 100644 --- a/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json +++ b/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.102", + "version": "8.0.117", "rollForward": "feature" } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/SampleTypeSpecContext.cs b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/SampleTypeSpecContext.cs index 588aff0bc8e..22a54ca30ba 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/SampleTypeSpecContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/SampleTypeSpecContext.cs @@ -6,6 +6,7 @@ #nullable disable using System.ClientModel.Primitives; +using SampleTypeSpec.Models.Custom; namespace SampleTypeSpec { @@ -13,6 +14,17 @@ namespace SampleTypeSpec /// Context class which will be filled in by the System.ClientModel.SourceGeneration. /// For more information /// + [ModelReaderWriterBuildable(typeof(Thing))] + [ModelReaderWriterBuildable(typeof(RoundTripModel))] + [ModelReaderWriterBuildable(typeof(ModelWithRequiredNullableProperties))] + [ModelReaderWriterBuildable(typeof(Friend))] + [ModelReaderWriterBuildable(typeof(RenamedModelCustom))] + [ModelReaderWriterBuildable(typeof(ReturnsAnonymousModelResponse))] + [ModelReaderWriterBuildable(typeof(ListWithNextLinkResponse))] + [ModelReaderWriterBuildable(typeof(ListWithContinuationTokenResponse))] + [ModelReaderWriterBuildable(typeof(ListWithContinuationTokenHeaderResponseResponse))] + [ModelReaderWriterBuildable(typeof(PageThing))] + [ModelReaderWriterBuildable(typeof(ModelWithEmbeddedNonBodyParameters))] public partial class SampleTypeSpecContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/global.json b/packages/http-client-csharp/global.json index ef491491b99..42bb9956fc0 100644 --- a/packages/http-client-csharp/global.json +++ b/packages/http-client-csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.102", + "version": "8.0.117", "rollForward": "feature" } } From c748252f5ad96d81f81541a137abe41c5c2bef27 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 21:39:51 +0000 Subject: [PATCH 06/21] Revert global.json changes and add comprehensive ModelReaderWriterContextDefinition tests Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../src/Generated/SampleTypeSpecClient.cs | 1788 ++++++++++++++--- .../logging/Logging.Plugin/src/global.json | 2 +- ...ModelReaderWriterContextDefinitionTests.cs | 157 ++ packages/http-client-csharp/global.json | 2 +- 4 files changed, 1638 insertions(+), 311 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs diff --git a/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs b/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs index 5377c494caa..da04f3625b5 100644 --- a/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs +++ b/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/SampleTypeSpecClient.cs @@ -72,11 +72,24 @@ public SampleTypeSpecClient(Uri endpoint, ApiKeyCredential keyCredential, Sample /// The response returned from the service. public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery, RequestOptions options) { - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method SayHi."); + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method SayHi: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method SayHi."); + } } /// @@ -96,11 +109,24 @@ public virtual ClientResult SayHi(string headParameter, string queryParameter, s /// The response returned from the service. public virtual async Task SayHiAsync(string headParameter, string queryParameter, string optionalQuery, RequestOptions options) { - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method SayHiAsync."); + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + using PipelineMessage message = CreateSayHiRequest(headParameter, queryParameter, optionalQuery, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method SayHiAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method SayHiAsync."); + } } /// Return hi. @@ -112,11 +138,24 @@ public virtual async Task SayHiAsync(string headParameter, string /// Service returned a non-success status code. public virtual ClientResult SayHi(string headParameter, string queryParameter, string optionalQuery = default, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method SayHi."); + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + ClientResult result = SayHi(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method SayHi: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method SayHi."); + } } /// Return hi. @@ -128,11 +167,24 @@ public virtual ClientResult SayHi(string headParameter, string queryParam /// Service returned a non-success status code. public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = default, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(headParameter, nameof(headParameter)); - Argument.AssertNotNull(queryParameter, nameof(queryParameter)); - - ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method SayHiAsync."); + Argument.AssertNotNull(headParameter, nameof(headParameter)); + Argument.AssertNotNull(queryParameter, nameof(queryParameter)); + + ClientResult result = await SayHiAsync(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method SayHiAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method SayHiAsync."); + } } /// @@ -152,12 +204,25 @@ public virtual async Task> SayHiAsync(string headParameter, /// The response returned from the service. public virtual ClientResult HelloAgain(string p2, string p1, BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method HelloAgain."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloAgain: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloAgain."); + } } /// @@ -177,12 +242,25 @@ public virtual ClientResult HelloAgain(string p2, string p1, BinaryContent conte /// The response returned from the service. public virtual async Task HelloAgainAsync(string p2, string p1, BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method HelloAgainAsync."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHelloAgainRequest(p2, p1, content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloAgainAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloAgainAsync."); + } } /// Return hi again. @@ -194,12 +272,25 @@ public virtual async Task HelloAgainAsync(string p2, string p1, Bi /// Service returned a non-success status code. public virtual ClientResult HelloAgain(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(action, nameof(action)); - - ClientResult result = HelloAgain(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloAgain."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(action, nameof(action)); + + ClientResult result = HelloAgain(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloAgain: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloAgain."); + } } /// Return hi again. @@ -211,12 +302,25 @@ public virtual ClientResult HelloAgain(string p2, string p1, Rou /// Service returned a non-success status code. public virtual async Task> HelloAgainAsync(string p2, string p1, RoundTripModel action, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(action, nameof(action)); - - ClientResult result = await HelloAgainAsync(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloAgainAsync."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(action, nameof(action)); + + ClientResult result = await HelloAgainAsync(p2, p1, action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloAgainAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloAgainAsync."); + } } /// @@ -236,12 +340,25 @@ public virtual async Task> HelloAgainAsync(string p /// The response returned from the service. public virtual ClientResult NoContentType(string p2, string p1, BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method NoContentType."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method NoContentType: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method NoContentType."); + } } /// @@ -261,12 +378,25 @@ public virtual ClientResult NoContentType(string p2, string p1, BinaryContent co /// The response returned from the service. public virtual async Task NoContentTypeAsync(string p2, string p1, BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(p2, nameof(p2)); - Argument.AssertNotNull(p1, nameof(p1)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method NoContentTypeAsync."); + Argument.AssertNotNull(p2, nameof(p2)); + Argument.AssertNotNull(p1, nameof(p1)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateNoContentTypeRequest(p2, p1, content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method NoContentTypeAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method NoContentTypeAsync."); + } } /// @@ -282,8 +412,21 @@ public virtual async Task NoContentTypeAsync(string p2, string p1, /// The response returned from the service. public virtual ClientResult HelloDemo2(RequestOptions options) { - using PipelineMessage message = CreateHelloDemo2Request(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method HelloDemo2."); + using PipelineMessage message = CreateHelloDemo2Request(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloDemo2: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloDemo2."); + } } /// @@ -299,8 +442,21 @@ public virtual ClientResult HelloDemo2(RequestOptions options) /// The response returned from the service. public virtual async Task HelloDemo2Async(RequestOptions options) { - using PipelineMessage message = CreateHelloDemo2Request(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method HelloDemo2Async."); + using PipelineMessage message = CreateHelloDemo2Request(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloDemo2Async: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloDemo2Async."); + } } /// Return hi in demo2. @@ -308,8 +464,21 @@ public virtual async Task HelloDemo2Async(RequestOptions options) /// Service returned a non-success status code. public virtual ClientResult HelloDemo2(CancellationToken cancellationToken = default) { - ClientResult result = HelloDemo2(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloDemo2."); + ClientResult result = HelloDemo2(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloDemo2: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloDemo2."); + } } /// Return hi in demo2. @@ -317,8 +486,21 @@ public virtual ClientResult HelloDemo2(CancellationToken cancellationToke /// Service returned a non-success status code. public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default) { - ClientResult result = await HelloDemo2Async(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloDemo2Async."); + ClientResult result = await HelloDemo2Async(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloDemo2Async: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloDemo2Async."); + } } /// @@ -336,10 +518,23 @@ public virtual async Task> HelloDemo2Async(CancellationToken /// The response returned from the service. public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateCreateLiteralRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method CreateLiteral."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateLiteralRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method CreateLiteral: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method CreateLiteral."); + } } /// @@ -357,10 +552,23 @@ public virtual ClientResult CreateLiteral(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task CreateLiteralAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateCreateLiteralRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method CreateLiteralAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateLiteralRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method CreateLiteralAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method CreateLiteralAsync."); + } } /// Create with literal value. @@ -370,10 +578,23 @@ public virtual async Task CreateLiteralAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult CreateLiteral(Thing body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = CreateLiteral(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method CreateLiteral."); + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = CreateLiteral(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method CreateLiteral: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method CreateLiteral."); + } } /// Create with literal value. @@ -383,10 +604,23 @@ public virtual ClientResult CreateLiteral(Thing body, CancellationToken c /// Service returned a non-success status code. public virtual async Task> CreateLiteralAsync(Thing body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = await CreateLiteralAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method CreateLiteralAsync."); + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = await CreateLiteralAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method CreateLiteralAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method CreateLiteralAsync."); + } } /// @@ -402,8 +636,21 @@ public virtual async Task> CreateLiteralAsync(Thing body, Ca /// The response returned from the service. public virtual ClientResult HelloLiteral(RequestOptions options) { - using PipelineMessage message = CreateHelloLiteralRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method HelloLiteral."); + using PipelineMessage message = CreateHelloLiteralRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloLiteral: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloLiteral."); + } } /// @@ -419,8 +666,21 @@ public virtual ClientResult HelloLiteral(RequestOptions options) /// The response returned from the service. public virtual async Task HelloLiteralAsync(RequestOptions options) { - using PipelineMessage message = CreateHelloLiteralRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method HelloLiteralAsync."); + using PipelineMessage message = CreateHelloLiteralRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloLiteralAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloLiteralAsync."); + } } /// Send literal parameters. @@ -428,8 +688,21 @@ public virtual async Task HelloLiteralAsync(RequestOptions options /// Service returned a non-success status code. public virtual ClientResult HelloLiteral(CancellationToken cancellationToken = default) { - ClientResult result = HelloLiteral(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloLiteral."); + ClientResult result = HelloLiteral(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloLiteral: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloLiteral."); + } } /// Send literal parameters. @@ -437,8 +710,21 @@ public virtual ClientResult HelloLiteral(CancellationToken cancellationTo /// Service returned a non-success status code. public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default) { - ClientResult result = await HelloLiteralAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method HelloLiteralAsync."); + ClientResult result = await HelloLiteralAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HelloLiteralAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HelloLiteralAsync."); + } } /// @@ -455,8 +741,21 @@ public virtual async Task> HelloLiteralAsync(CancellationTok /// The response returned from the service. public virtual ClientResult TopAction(DateTimeOffset action, RequestOptions options) { - using PipelineMessage message = CreateTopActionRequest(action, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method TopAction."); + using PipelineMessage message = CreateTopActionRequest(action, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopAction: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopAction."); + } } /// @@ -473,8 +772,21 @@ public virtual ClientResult TopAction(DateTimeOffset action, RequestOptions opti /// The response returned from the service. public virtual async Task TopActionAsync(DateTimeOffset action, RequestOptions options) { - using PipelineMessage message = CreateTopActionRequest(action, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method TopActionAsync."); + using PipelineMessage message = CreateTopActionRequest(action, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopActionAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopActionAsync."); + } } /// top level method. @@ -483,8 +795,21 @@ public virtual async Task TopActionAsync(DateTimeOffset action, Re /// Service returned a non-success status code. public virtual ClientResult TopAction(DateTimeOffset action, CancellationToken cancellationToken = default) { - ClientResult result = TopAction(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method TopAction."); + ClientResult result = TopAction(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopAction: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopAction."); + } } /// top level method. @@ -493,8 +818,21 @@ public virtual ClientResult TopAction(DateTimeOffset action, Cancellation /// Service returned a non-success status code. public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default) { - ClientResult result = await TopActionAsync(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method TopActionAsync."); + ClientResult result = await TopActionAsync(action, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopActionAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopActionAsync."); + } } /// @@ -510,8 +848,21 @@ public virtual async Task> TopActionAsync(DateTimeOffset act /// The response returned from the service. public virtual ClientResult TopAction2(RequestOptions options) { - using PipelineMessage message = CreateTopAction2Request(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method TopAction2."); + using PipelineMessage message = CreateTopAction2Request(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopAction2: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopAction2."); + } } /// @@ -527,8 +878,21 @@ public virtual ClientResult TopAction2(RequestOptions options) /// The response returned from the service. public virtual async Task TopAction2Async(RequestOptions options) { - using PipelineMessage message = CreateTopAction2Request(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method TopAction2Async."); + using PipelineMessage message = CreateTopAction2Request(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method TopAction2Async: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method TopAction2Async."); + } } /// @@ -546,10 +910,23 @@ public virtual async Task TopAction2Async(RequestOptions options) /// The response returned from the service. public virtual ClientResult PatchAction(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreatePatchActionRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method PatchAction."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePatchActionRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method PatchAction: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method PatchAction."); + } } /// @@ -567,10 +944,23 @@ public virtual ClientResult PatchAction(BinaryContent content, RequestOptions op /// The response returned from the service. public virtual async Task PatchActionAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreatePatchActionRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method PatchActionAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePatchActionRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method PatchActionAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method PatchActionAsync."); + } } /// @@ -588,10 +978,23 @@ public virtual async Task PatchActionAsync(BinaryContent content, /// The response returned from the service. public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateAnonymousBodyRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method AnonymousBody."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAnonymousBodyRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AnonymousBody: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AnonymousBody."); + } } /// @@ -609,10 +1012,23 @@ public virtual ClientResult AnonymousBody(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task AnonymousBodyAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateAnonymousBodyRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method AnonymousBodyAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAnonymousBodyRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AnonymousBodyAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AnonymousBodyAsync."); + } } /// body parameter without body decorator. @@ -636,30 +1052,43 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult AnonymousBody(string name, BinaryData requiredUnion, string requiredLiteralString, string requiredNullableString, int requiredLiteralInt, float requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, string optionalLiteralString = default, int? optionalLiteralInt = default, float? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); - Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); - Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); - - Thing spreadModel = new Thing( - name, - requiredUnion, - requiredLiteralString, - requiredNullableString, - optionalNullableString, - requiredLiteralInt, - requiredLiteralFloat, - requiredLiteralBool, - optionalLiteralString, - optionalLiteralInt, - optionalLiteralFloat, - optionalLiteralBool, - requiredBadDescription, - optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), - requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), - null); - ClientResult result = AnonymousBody(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method AnonymousBody."); + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); + Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); + Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); + + Thing spreadModel = new Thing( + name, + requiredUnion, + requiredLiteralString, + requiredNullableString, + optionalNullableString, + requiredLiteralInt, + requiredLiteralFloat, + requiredLiteralBool, + optionalLiteralString, + optionalLiteralInt, + optionalLiteralFloat, + optionalLiteralBool, + requiredBadDescription, + optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), + requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), + null); + ClientResult result = AnonymousBody(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AnonymousBody: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AnonymousBody."); + } } /// body parameter without body decorator. @@ -683,30 +1112,43 @@ public virtual ClientResult AnonymousBody(string name, BinaryData require /// Service returned a non-success status code. public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, string requiredLiteralString, string requiredNullableString, int requiredLiteralInt, float requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, string optionalLiteralString = default, int? optionalLiteralInt = default, float? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); - Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); - Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); - - Thing spreadModel = new Thing( - name, - requiredUnion, - requiredLiteralString, - requiredNullableString, - optionalNullableString, - requiredLiteralInt, - requiredLiteralFloat, - requiredLiteralBool, - optionalLiteralString, - optionalLiteralInt, - optionalLiteralFloat, - optionalLiteralBool, - requiredBadDescription, - optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), - requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), - null); - ClientResult result = await AnonymousBodyAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method AnonymousBodyAsync."); + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); + Argument.AssertNotNull(requiredLiteralString, nameof(requiredLiteralString)); + Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription)); + + Thing spreadModel = new Thing( + name, + requiredUnion, + requiredLiteralString, + requiredNullableString, + optionalNullableString, + requiredLiteralInt, + requiredLiteralFloat, + requiredLiteralBool, + optionalLiteralString, + optionalLiteralInt, + optionalLiteralFloat, + optionalLiteralBool, + requiredBadDescription, + optionalNullableList?.ToList() as IList ?? new ChangeTrackingList(), + requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(), + null); + ClientResult result = await AnonymousBodyAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AnonymousBodyAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AnonymousBodyAsync."); + } } /// @@ -724,10 +1166,23 @@ public virtual async Task> AnonymousBodyAsync(string name, B /// The response returned from the service. public virtual ClientResult FriendlyModel(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateFriendlyModelRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method FriendlyModel."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateFriendlyModelRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method FriendlyModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method FriendlyModel."); + } } /// @@ -745,10 +1200,23 @@ public virtual ClientResult FriendlyModel(BinaryContent content, RequestOptions /// The response returned from the service. public virtual async Task FriendlyModelAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateFriendlyModelRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method FriendlyModelAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateFriendlyModelRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method FriendlyModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method FriendlyModelAsync."); + } } /// Model can have its friendly name. @@ -758,11 +1226,24 @@ public virtual async Task FriendlyModelAsync(BinaryContent content /// Service returned a non-success status code. public virtual ClientResult FriendlyModel(string name, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - - Friend spreadModel = new Friend(name, null); - ClientResult result = FriendlyModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Friend)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method FriendlyModel."); + Argument.AssertNotNull(name, nameof(name)); + + Friend spreadModel = new Friend(name, null); + ClientResult result = FriendlyModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Friend)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method FriendlyModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method FriendlyModel."); + } } /// Model can have its friendly name. @@ -772,11 +1253,24 @@ public virtual ClientResult FriendlyModel(string name, CancellationToken /// Service returned a non-success status code. public virtual async Task> FriendlyModelAsync(string name, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - - Friend spreadModel = new Friend(name, null); - ClientResult result = await FriendlyModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Friend)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method FriendlyModelAsync."); + Argument.AssertNotNull(name, nameof(name)); + + Friend spreadModel = new Friend(name, null); + ClientResult result = await FriendlyModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Friend)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method FriendlyModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method FriendlyModelAsync."); + } } /// @@ -792,8 +1286,21 @@ public virtual async Task> FriendlyModelAsync(string name, /// The response returned from the service. public virtual ClientResult AddTimeHeader(RequestOptions options) { - using PipelineMessage message = CreateAddTimeHeaderRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method AddTimeHeader."); + using PipelineMessage message = CreateAddTimeHeaderRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AddTimeHeader: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AddTimeHeader."); + } } /// @@ -809,8 +1316,21 @@ public virtual ClientResult AddTimeHeader(RequestOptions options) /// The response returned from the service. public virtual async Task AddTimeHeaderAsync(RequestOptions options) { - using PipelineMessage message = CreateAddTimeHeaderRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method AddTimeHeaderAsync."); + using PipelineMessage message = CreateAddTimeHeaderRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AddTimeHeaderAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AddTimeHeaderAsync."); + } } /// addTimeHeader. @@ -818,7 +1338,20 @@ public virtual async Task AddTimeHeaderAsync(RequestOptions option /// Service returned a non-success status code. public virtual ClientResult AddTimeHeader(CancellationToken cancellationToken = default) { - return AddTimeHeader(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method AddTimeHeader."); + return AddTimeHeader(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AddTimeHeader: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AddTimeHeader."); + } } /// addTimeHeader. @@ -826,7 +1359,20 @@ public virtual ClientResult AddTimeHeader(CancellationToken cancellationToken = /// Service returned a non-success status code. public virtual async Task AddTimeHeaderAsync(CancellationToken cancellationToken = default) { - return await AddTimeHeaderAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + try + { + System.Console.WriteLine("Entering method AddTimeHeaderAsync."); + return await AddTimeHeaderAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method AddTimeHeaderAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method AddTimeHeaderAsync."); + } } /// @@ -844,10 +1390,23 @@ public virtual async Task AddTimeHeaderAsync(CancellationToken can /// The response returned from the service. public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateProjectedNameModelRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method ProjectedNameModel."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateProjectedNameModelRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ProjectedNameModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ProjectedNameModel."); + } } /// @@ -865,10 +1424,23 @@ public virtual ClientResult ProjectedNameModel(BinaryContent content, RequestOpt /// The response returned from the service. public virtual async Task ProjectedNameModelAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateProjectedNameModelRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method ProjectedNameModelAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateProjectedNameModelRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ProjectedNameModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ProjectedNameModelAsync."); + } } /// Model can have its projected name. @@ -878,11 +1450,24 @@ public virtual async Task ProjectedNameModelAsync(BinaryContent co /// Service returned a non-success status code. public virtual ClientResult ProjectedNameModel(string name, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - - RenamedModel spreadModel = new RenamedModel(name, null); - ClientResult result = ProjectedNameModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method ProjectedNameModel."); + Argument.AssertNotNull(name, nameof(name)); + + RenamedModel spreadModel = new RenamedModel(name, null); + ClientResult result = ProjectedNameModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ProjectedNameModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ProjectedNameModel."); + } } /// Model can have its projected name. @@ -892,11 +1477,24 @@ public virtual ClientResult ProjectedNameModel(string name, Cancel /// Service returned a non-success status code. public virtual async Task> ProjectedNameModelAsync(string name, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(name, nameof(name)); - - RenamedModel spreadModel = new RenamedModel(name, null); - ClientResult result = await ProjectedNameModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method ProjectedNameModelAsync."); + Argument.AssertNotNull(name, nameof(name)); + + RenamedModel spreadModel = new RenamedModel(name, null); + ClientResult result = await ProjectedNameModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((RenamedModel)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ProjectedNameModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ProjectedNameModelAsync."); + } } /// @@ -912,8 +1510,21 @@ public virtual async Task> ProjectedNameModelAsync(st /// The response returned from the service. public virtual ClientResult ReturnsAnonymousModel(RequestOptions options) { - using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method ReturnsAnonymousModel."); + using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ReturnsAnonymousModel."); + } } /// @@ -929,8 +1540,21 @@ public virtual ClientResult ReturnsAnonymousModel(RequestOptions options) /// The response returned from the service. public virtual async Task ReturnsAnonymousModelAsync(RequestOptions options) { - using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method ReturnsAnonymousModelAsync."); + using PipelineMessage message = CreateReturnsAnonymousModelRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ReturnsAnonymousModelAsync."); + } } /// return anonymous model. @@ -938,8 +1562,21 @@ public virtual async Task ReturnsAnonymousModelAsync(RequestOption /// Service returned a non-success status code. public virtual ClientResult ReturnsAnonymousModel(CancellationToken cancellationToken = default) { - ClientResult result = ReturnsAnonymousModel(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method ReturnsAnonymousModel."); + ClientResult result = ReturnsAnonymousModel(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModel: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ReturnsAnonymousModel."); + } } /// return anonymous model. @@ -947,8 +1584,21 @@ public virtual ClientResult ReturnsAnonymousModel /// Service returned a non-success status code. public virtual async Task> ReturnsAnonymousModelAsync(CancellationToken cancellationToken = default) { - ClientResult result = await ReturnsAnonymousModelAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method ReturnsAnonymousModelAsync."); + ClientResult result = await ReturnsAnonymousModelAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((ReturnsAnonymousModelResponse)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ReturnsAnonymousModelAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ReturnsAnonymousModelAsync."); + } } /// @@ -966,10 +1616,23 @@ public virtual async Task> ReturnsAn /// The response returned from the service. public virtual ClientResult GetUnknownValue(string accept, RequestOptions options) { - Argument.AssertNotNull(accept, nameof(accept)); - - using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method GetUnknownValue."); + Argument.AssertNotNull(accept, nameof(accept)); + + using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method GetUnknownValue: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method GetUnknownValue."); + } } /// @@ -987,10 +1650,23 @@ public virtual ClientResult GetUnknownValue(string accept, RequestOptions option /// The response returned from the service. public virtual async Task GetUnknownValueAsync(string accept, RequestOptions options) { - Argument.AssertNotNull(accept, nameof(accept)); - - using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method GetUnknownValueAsync."); + Argument.AssertNotNull(accept, nameof(accept)); + + using PipelineMessage message = CreateGetUnknownValueRequest(accept, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method GetUnknownValueAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method GetUnknownValueAsync."); + } } /// get extensible enum. @@ -1000,10 +1676,23 @@ public virtual async Task GetUnknownValueAsync(string accept, Requ /// Service returned a non-success status code. public virtual ClientResult GetUnknownValue(string accept, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(accept, nameof(accept)); - - ClientResult result = GetUnknownValue(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method GetUnknownValue."); + Argument.AssertNotNull(accept, nameof(accept)); + + ClientResult result = GetUnknownValue(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method GetUnknownValue: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method GetUnknownValue."); + } } /// get extensible enum. @@ -1013,10 +1702,23 @@ public virtual ClientResult GetUnknownValue(string accept, CancellationT /// Service returned a non-success status code. public virtual async Task> GetUnknownValueAsync(string accept, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(accept, nameof(accept)); - - ClientResult result = await GetUnknownValueAsync(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method GetUnknownValueAsync."); + Argument.AssertNotNull(accept, nameof(accept)); + + ClientResult result = await GetUnknownValueAsync(accept, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue(result.GetRawResponse().Content.ToString(), result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method GetUnknownValueAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method GetUnknownValueAsync."); + } } /// @@ -1034,10 +1736,23 @@ public virtual async Task> GetUnknownValueAsync(string acce /// The response returned from the service. public virtual ClientResult InternalProtocol(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateInternalProtocolRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method InternalProtocol."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateInternalProtocolRequest(content, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method InternalProtocol: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method InternalProtocol."); + } } /// @@ -1055,10 +1770,23 @@ public virtual ClientResult InternalProtocol(BinaryContent content, RequestOptio /// The response returned from the service. public virtual async Task InternalProtocolAsync(BinaryContent content, RequestOptions options = null) { - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateInternalProtocolRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method InternalProtocolAsync."); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateInternalProtocolRequest(content, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method InternalProtocolAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method InternalProtocolAsync."); + } } /// When set protocol false and convenient true, then the protocol method should be internal. @@ -1068,10 +1796,23 @@ public virtual async Task InternalProtocolAsync(BinaryContent cont /// Service returned a non-success status code. public virtual ClientResult InternalProtocol(Thing body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = InternalProtocol(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method InternalProtocol."); + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = InternalProtocol(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method InternalProtocol: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method InternalProtocol."); + } } /// When set protocol false and convenient true, then the protocol method should be internal. @@ -1081,10 +1822,23 @@ public virtual ClientResult InternalProtocol(Thing body, CancellationToke /// Service returned a non-success status code. public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); - - ClientResult result = await InternalProtocolAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); - return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + try + { + System.Console.WriteLine("Entering method InternalProtocolAsync."); + Argument.AssertNotNull(body, nameof(body)); + + ClientResult result = await InternalProtocolAsync(body, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return ClientResult.FromValue((Thing)result, result.GetRawResponse()); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method InternalProtocolAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method InternalProtocolAsync."); + } } /// @@ -1100,8 +1854,21 @@ public virtual async Task> InternalProtocolAsync(Thing body, /// The response returned from the service. public virtual ClientResult StillConvenient(RequestOptions options) { - using PipelineMessage message = CreateStillConvenientRequest(options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method StillConvenient."); + using PipelineMessage message = CreateStillConvenientRequest(options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method StillConvenient: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method StillConvenient."); + } } /// @@ -1117,8 +1884,21 @@ public virtual ClientResult StillConvenient(RequestOptions options) /// The response returned from the service. public virtual async Task StillConvenientAsync(RequestOptions options) { - using PipelineMessage message = CreateStillConvenientRequest(options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method StillConvenientAsync."); + using PipelineMessage message = CreateStillConvenientRequest(options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method StillConvenientAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method StillConvenientAsync."); + } } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. @@ -1126,7 +1906,20 @@ public virtual async Task StillConvenientAsync(RequestOptions opti /// Service returned a non-success status code. public virtual ClientResult StillConvenient(CancellationToken cancellationToken = default) { - return StillConvenient(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method StillConvenient."); + return StillConvenient(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method StillConvenient: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method StillConvenient."); + } } /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. @@ -1134,7 +1927,20 @@ public virtual ClientResult StillConvenient(CancellationToken cancellationToken /// Service returned a non-success status code. public virtual async Task StillConvenientAsync(CancellationToken cancellationToken = default) { - return await StillConvenientAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + try + { + System.Console.WriteLine("Entering method StillConvenientAsync."); + return await StillConvenientAsync(cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method StillConvenientAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method StillConvenientAsync."); + } } /// @@ -1152,10 +1958,23 @@ public virtual async Task StillConvenientAsync(CancellationToken c /// The response returned from the service. public virtual ClientResult HeadAsBoolean(string id, RequestOptions options) { - Argument.AssertNotNull(id, nameof(id)); - - using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method HeadAsBoolean."); + Argument.AssertNotNull(id, nameof(id)); + + using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HeadAsBoolean: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HeadAsBoolean."); + } } /// @@ -1173,10 +1992,23 @@ public virtual ClientResult HeadAsBoolean(string id, RequestOptions options) /// The response returned from the service. public virtual async Task HeadAsBooleanAsync(string id, RequestOptions options) { - Argument.AssertNotNull(id, nameof(id)); - - using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method HeadAsBooleanAsync."); + Argument.AssertNotNull(id, nameof(id)); + + using PipelineMessage message = CreateHeadAsBooleanRequest(id, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HeadAsBooleanAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HeadAsBooleanAsync."); + } } /// head as boolean. @@ -1186,9 +2018,22 @@ public virtual async Task HeadAsBooleanAsync(string id, RequestOpt /// Service returned a non-success status code. public virtual ClientResult HeadAsBoolean(string id, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(id, nameof(id)); + try + { + System.Console.WriteLine("Entering method HeadAsBoolean."); + Argument.AssertNotNull(id, nameof(id)); - return HeadAsBoolean(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return HeadAsBoolean(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HeadAsBoolean: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HeadAsBoolean."); + } } /// head as boolean. @@ -1198,9 +2043,22 @@ public virtual ClientResult HeadAsBoolean(string id, CancellationToken cancellat /// Service returned a non-success status code. public virtual async Task HeadAsBooleanAsync(string id, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(id, nameof(id)); + try + { + System.Console.WriteLine("Entering method HeadAsBooleanAsync."); + Argument.AssertNotNull(id, nameof(id)); - return await HeadAsBooleanAsync(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return await HeadAsBooleanAsync(id, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method HeadAsBooleanAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method HeadAsBooleanAsync."); + } } /// @@ -1218,10 +2076,23 @@ public virtual async Task HeadAsBooleanAsync(string id, Cancellati /// The response returned from the service. public virtual ClientResult WithApiVersion(string p1, RequestOptions options) { - Argument.AssertNotNull(p1, nameof(p1)); - - using PipelineMessage message = CreateWithApiVersionRequest(p1, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method WithApiVersion."); + Argument.AssertNotNull(p1, nameof(p1)); + + using PipelineMessage message = CreateWithApiVersionRequest(p1, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method WithApiVersion: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method WithApiVersion."); + } } /// @@ -1239,10 +2110,23 @@ public virtual ClientResult WithApiVersion(string p1, RequestOptions options) /// The response returned from the service. public virtual async Task WithApiVersionAsync(string p1, RequestOptions options) { - Argument.AssertNotNull(p1, nameof(p1)); - - using PipelineMessage message = CreateWithApiVersionRequest(p1, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method WithApiVersionAsync."); + Argument.AssertNotNull(p1, nameof(p1)); + + using PipelineMessage message = CreateWithApiVersionRequest(p1, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method WithApiVersionAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method WithApiVersionAsync."); + } } /// Return hi again. @@ -1252,9 +2136,22 @@ public virtual async Task WithApiVersionAsync(string p1, RequestOp /// Service returned a non-success status code. public virtual ClientResult WithApiVersion(string p1, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(p1, nameof(p1)); + try + { + System.Console.WriteLine("Entering method WithApiVersion."); + Argument.AssertNotNull(p1, nameof(p1)); - return WithApiVersion(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return WithApiVersion(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method WithApiVersion: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method WithApiVersion."); + } } /// Return hi again. @@ -1264,9 +2161,22 @@ public virtual ClientResult WithApiVersion(string p1, CancellationToken cancella /// Service returned a non-success status code. public virtual async Task WithApiVersionAsync(string p1, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(p1, nameof(p1)); + try + { + System.Console.WriteLine("Entering method WithApiVersionAsync."); + Argument.AssertNotNull(p1, nameof(p1)); - return await WithApiVersionAsync(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return await WithApiVersionAsync(p1, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method WithApiVersionAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method WithApiVersionAsync."); + } } /// @@ -1282,7 +2192,20 @@ public virtual async Task WithApiVersionAsync(string p1, Cancellat /// The response returned from the service. public virtual CollectionResult ListWithNextLink(RequestOptions options) { - return new SampleTypeSpecClientListWithNextLinkCollectionResult(this, null, options); + try + { + System.Console.WriteLine("Entering method ListWithNextLink."); + return new SampleTypeSpecClientListWithNextLinkCollectionResult(this, null, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithNextLink: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithNextLink."); + } } /// @@ -1298,7 +2221,20 @@ public virtual CollectionResult ListWithNextLink(RequestOptions options) /// The response returned from the service. public virtual AsyncCollectionResult ListWithNextLinkAsync(RequestOptions options) { - return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResult(this, null, options); + try + { + System.Console.WriteLine("Entering method ListWithNextLinkAsync."); + return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResult(this, null, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithNextLinkAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithNextLinkAsync."); + } } /// List things with nextlink. @@ -1306,7 +2242,20 @@ public virtual AsyncCollectionResult ListWithNextLinkAsync(RequestOptions option /// Service returned a non-success status code. public virtual CollectionResult ListWithNextLink(CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithNextLinkCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithNextLink."); + return new SampleTypeSpecClientListWithNextLinkCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithNextLink: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithNextLink."); + } } /// List things with nextlink. @@ -1314,7 +2263,20 @@ public virtual CollectionResult ListWithNextLink(CancellationToken cancel /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithNextLinkAsync(CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithNextLinkAsync."); + return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithNextLinkAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithNextLinkAsync."); + } } /// @@ -1331,7 +2293,20 @@ public virtual AsyncCollectionResult ListWithNextLinkAsync(CancellationTo /// The response returned from the service. public virtual CollectionResult ListWithContinuationToken(string token, RequestOptions options) { - return new SampleTypeSpecClientListWithContinuationTokenCollectionResult(this, token, options); + try + { + System.Console.WriteLine("Entering method ListWithContinuationToken."); + return new SampleTypeSpecClientListWithContinuationTokenCollectionResult(this, token, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationToken: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationToken."); + } } /// @@ -1348,7 +2323,20 @@ public virtual CollectionResult ListWithContinuationToken(string token, RequestO /// The response returned from the service. public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token, RequestOptions options) { - return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResult(this, token, options); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenAsync."); + return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResult(this, token, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenAsync."); + } } /// List things with continuation token. @@ -1357,7 +2345,20 @@ public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token /// Service returned a non-success status code. public virtual CollectionResult ListWithContinuationToken(string token = default, CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithContinuationTokenCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithContinuationToken."); + return new SampleTypeSpecClientListWithContinuationTokenCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationToken: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationToken."); + } } /// List things with continuation token. @@ -1366,7 +2367,20 @@ public virtual CollectionResult ListWithContinuationToken(string token = /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token = default, CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenAsync."); + return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenAsync."); + } } /// @@ -1383,7 +2397,20 @@ public virtual AsyncCollectionResult ListWithContinuationTokenAsync(strin /// The response returned from the service. public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string token, RequestOptions options) { - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResult(this, token, options); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponse."); + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResult(this, token, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponse: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponse."); + } } /// @@ -1400,7 +2427,20 @@ public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string t /// The response returned from the service. public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsync(string token, RequestOptions options) { - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResult(this, token, options); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponseAsync."); + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResult(this, token, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponseAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponseAsync."); + } } /// List things with continuation token header response. @@ -1409,7 +2449,20 @@ public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsyn /// Service returned a non-success status code. public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string token = default, CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponse."); + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponse: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponse."); + } } /// List things with continuation token header response. @@ -1418,7 +2471,20 @@ public virtual CollectionResult ListWithContinuationTokenHeaderResponse(s /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsync(string token = default, CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithContinuationTokenHeaderResponseAsync."); + return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithContinuationTokenHeaderResponseAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithContinuationTokenHeaderResponseAsync."); + } } /// @@ -1434,7 +2500,20 @@ public virtual AsyncCollectionResult ListWithContinuationTokenHeaderRespo /// The response returned from the service. public virtual CollectionResult ListWithPaging(RequestOptions options) { - return new SampleTypeSpecClientListWithPagingCollectionResult(this, options); + try + { + System.Console.WriteLine("Entering method ListWithPaging."); + return new SampleTypeSpecClientListWithPagingCollectionResult(this, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithPaging: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithPaging."); + } } /// @@ -1450,7 +2529,20 @@ public virtual CollectionResult ListWithPaging(RequestOptions options) /// The response returned from the service. public virtual AsyncCollectionResult ListWithPagingAsync(RequestOptions options) { - return new SampleTypeSpecClientListWithPagingAsyncCollectionResult(this, options); + try + { + System.Console.WriteLine("Entering method ListWithPagingAsync."); + return new SampleTypeSpecClientListWithPagingAsyncCollectionResult(this, options); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithPagingAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithPagingAsync."); + } } /// List things with paging. @@ -1458,7 +2550,20 @@ public virtual AsyncCollectionResult ListWithPagingAsync(RequestOptions options) /// Service returned a non-success status code. public virtual CollectionResult ListWithPaging(CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithPagingCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithPaging."); + return new SampleTypeSpecClientListWithPagingCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithPaging: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithPaging."); + } } /// List things with paging. @@ -1466,7 +2571,20 @@ public virtual CollectionResult ListWithPaging(CancellationToken cancella /// Service returned a non-success status code. public virtual AsyncCollectionResult ListWithPagingAsync(CancellationToken cancellationToken = default) { - return new SampleTypeSpecClientListWithPagingAsyncCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + try + { + System.Console.WriteLine("Entering method ListWithPagingAsync."); + return new SampleTypeSpecClientListWithPagingAsyncCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method ListWithPagingAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method ListWithPagingAsync."); + } } /// @@ -1488,12 +2606,25 @@ public virtual AsyncCollectionResult ListWithPagingAsync(CancellationToke /// The response returned from the service. public virtual ClientResult EmbeddedParameters(string requiredHeader, string requiredQuery, BinaryContent content, string optionalHeader = default, string optionalQuery = default, RequestOptions options = null) { - Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); - Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + try + { + System.Console.WriteLine("Entering method EmbeddedParameters."); + Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); + Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); + return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method EmbeddedParameters: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method EmbeddedParameters."); + } } /// @@ -1515,12 +2646,25 @@ public virtual ClientResult EmbeddedParameters(string requiredHeader, string req /// The response returned from the service. public virtual async Task EmbeddedParametersAsync(string requiredHeader, string requiredQuery, BinaryContent content, string optionalHeader = default, string optionalQuery = default, RequestOptions options = null) { - Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); - Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); - Argument.AssertNotNull(content, nameof(content)); - - using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + try + { + System.Console.WriteLine("Entering method EmbeddedParametersAsync."); + Argument.AssertNotNull(requiredHeader, nameof(requiredHeader)); + Argument.AssertNotNull(requiredQuery, nameof(requiredQuery)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateEmbeddedParametersRequest(requiredHeader, requiredQuery, content, optionalHeader, optionalQuery, options); + return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method EmbeddedParametersAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method EmbeddedParametersAsync."); + } } /// An operation with embedded parameters within the body. @@ -1530,9 +2674,22 @@ public virtual async Task EmbeddedParametersAsync(string requiredH /// Service returned a non-success status code. public virtual ClientResult EmbeddedParameters(ModelWithEmbeddedNonBodyParameters body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); + try + { + System.Console.WriteLine("Entering method EmbeddedParameters."); + Argument.AssertNotNull(body, nameof(body)); - return EmbeddedParameters(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + return EmbeddedParameters(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method EmbeddedParameters: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method EmbeddedParameters."); + } } /// An operation with embedded parameters within the body. @@ -1542,9 +2699,22 @@ public virtual ClientResult EmbeddedParameters(ModelWithEmbeddedNonBodyParameter /// Service returned a non-success status code. public virtual async Task EmbeddedParametersAsync(ModelWithEmbeddedNonBodyParameters body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); - - return await EmbeddedParametersAsync(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + try + { + System.Console.WriteLine("Entering method EmbeddedParametersAsync."); + Argument.AssertNotNull(body, nameof(body)); + + return await EmbeddedParametersAsync(body.RequiredHeader, body.RequiredQuery, body, body.OptionalHeader, body.OptionalQuery, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + catch (Exception ex) + { + System.Console.WriteLine($"An exception was thrown in method EmbeddedParametersAsync: {ex}"); + throw; + } + finally + { + System.Console.WriteLine("Exiting method EmbeddedParametersAsync."); + } } } } diff --git a/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json b/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json index 42bb9956fc0..ef491491b99 100644 --- a/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json +++ b/docs/samples/client/csharp/plugins/logging/Logging.Plugin/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.117", + "version": "9.0.102", "rollForward": "feature" } } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs new file mode 100644 index 00000000000..7c05e842751 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Linq; +using Microsoft.TypeSpec.Generator.ClientModel.Providers; +using Microsoft.TypeSpec.Generator.ClientModel.Tests; +using Microsoft.TypeSpec.Generator.Input; +using Microsoft.TypeSpec.Generator.Primitives; +using Microsoft.TypeSpec.Generator.Providers; +using Microsoft.TypeSpec.Generator.Tests.Common; +using NUnit.Framework; + +namespace Microsoft.TypeSpec.Generator.ClientModel.Tests.Providers.Definitions +{ + public class ModelReaderWriterContextDefinitionTests + { + [Test] + public void ValidateModelReaderWriterContextIsGenerated() + { + MockHelpers.LoadMockGenerator(); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + + Assert.IsNotNull(contextDefinition); + Assert.IsNotNull(contextDefinition.Name); + Assert.IsTrue(contextDefinition.Name.EndsWith("Context")); + Assert.IsNotNull(contextDefinition.DeclarationModifiers); + Assert.IsTrue(contextDefinition.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public)); + Assert.IsTrue(contextDefinition.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Partial)); + Assert.IsTrue(contextDefinition.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Class)); + Assert.IsNotNull(contextDefinition.Implements); + Assert.IsTrue(contextDefinition.Implements.Contains(typeof(ModelReaderWriterContext))); + } + + [Test] + public void ValidateModelReaderWriterBuildableAttributesAreGenerated() + { + var mockGenerator = MockHelpers.LoadMockGenerator( + inputModels: () => new List + { + InputFactory.Model("TestModel", properties: new[] + { + InputFactory.Property("StringProperty", InputPrimitiveType.String), + InputFactory.Property("IntProperty", InputPrimitiveType.Int32) + }) + }); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + var attributes = contextDefinition.Attributes; + + Assert.IsNotNull(attributes); + Assert.IsTrue(attributes.Count > 0); + + // Check that at least one ModelReaderWriterBuildableAttribute exists + var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); + Assert.IsTrue(buildableAttributes.Any(), "At least one ModelReaderWriterBuildableAttribute should be generated"); + } + + [Test] + public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() + { + // Create a model with a property that references another model + var nestedModel = InputFactory.Model("NestedModel", properties: new[] + { + InputFactory.Property("NestedValue", InputPrimitiveType.String) + }); + + var parentModel = InputFactory.Model("ParentModel", properties: new[] + { + InputFactory.Property("NestedProperty", nestedModel), + InputFactory.Property("SimpleProperty", InputPrimitiveType.String) + }); + + var mockGenerator = MockHelpers.LoadMockGenerator( + inputModels: () => new List { parentModel, nestedModel }); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + var attributes = contextDefinition.Attributes; + + Assert.IsNotNull(attributes); + Assert.IsTrue(attributes.Count > 0); + + // Check that ModelReaderWriterBuildableAttribute exists for both models + var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); + Assert.IsTrue(buildableAttributes.Count() >= 2, "At least two ModelReaderWriterBuildableAttributes should be generated for nested models"); + } + + [Test] + public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperties() + { + // Create a model with a collection property containing another model + var itemModel = InputFactory.Model("ItemModel", properties: new[] + { + InputFactory.Property("ItemValue", InputPrimitiveType.String) + }); + + var collectionModel = InputFactory.Model("CollectionModel", properties: new[] + { + InputFactory.Property("Items", InputFactory.Array(itemModel)) + }); + + var mockGenerator = MockHelpers.LoadMockGenerator( + inputModels: () => new List { collectionModel, itemModel }); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + var attributes = contextDefinition.Attributes; + + Assert.IsNotNull(attributes); + Assert.IsTrue(attributes.Count > 0); + + // Check that ModelReaderWriterBuildableAttribute exists for both models + var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); + Assert.IsTrue(buildableAttributes.Count() >= 2, "At least two ModelReaderWriterBuildableAttributes should be generated for collection item models"); + } + + [Test] + public void ValidateModelReaderWriterBuildableAttributesAvoidDuplicates() + { + // Create models with circular references to test duplicate handling + var modelA = InputFactory.Model("ModelA", properties: new[] + { + InputFactory.Property("PropertyA", InputPrimitiveType.String) + }); + + var modelB = InputFactory.Model("ModelB", properties: new[] + { + InputFactory.Property("PropertyB", InputPrimitiveType.String), + InputFactory.Property("ModelARef", modelA) + }); + + // Add a property to ModelA that references ModelB to create a circular reference + var modelAWithCircularRef = InputFactory.Model("ModelA", properties: new[] + { + InputFactory.Property("PropertyA", InputPrimitiveType.String), + InputFactory.Property("ModelBRef", modelB) + }); + + var mockGenerator = MockHelpers.LoadMockGenerator( + inputModels: () => new List { modelAWithCircularRef, modelB }); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + var attributes = contextDefinition.Attributes; + + Assert.IsNotNull(attributes); + + // Check that no duplicate attributes exist + var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); + var uniqueTypes = buildableAttributes.Select(a => a.Arguments.First().ToString()).Distinct().ToList(); + + Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, + "No duplicate ModelReaderWriterBuildableAttributes should be generated"); + } + } +} \ No newline at end of file diff --git a/packages/http-client-csharp/global.json b/packages/http-client-csharp/global.json index 42bb9956fc0..ef491491b99 100644 --- a/packages/http-client-csharp/global.json +++ b/packages/http-client-csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.117", + "version": "9.0.102", "rollForward": "feature" } } From b18e0b0a7f77fb2cec156a39dc7b4432ab065c13 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:12:46 +0000 Subject: [PATCH 07/21] Fix ModelReaderWriterBuildableAttribute generation to ensure proper using statements Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../src/Providers/ModelReaderWriterContextDefinition.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index d86f5633be0..9f48e69731f 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -34,7 +34,9 @@ protected override IReadOnlyList BuildAttributes() var buildableTypes = CollectBuildableTypes(); foreach (var type in buildableTypes) { - attributes.Add(new AttributeStatement(typeof(ModelReaderWriterBuildableAttribute), TypeOf(type))); + // Use the full attribute type name to ensure proper compilation + var attributeType = new CSharpType(typeof(ModelReaderWriterBuildableAttribute)); + attributes.Add(new AttributeStatement(attributeType, TypeOf(type))); } return attributes; From 7c1c9957c6215785f209971d3f207d25a4f9dde5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:19:23 +0000 Subject: [PATCH 08/21] Update ModelReaderWriterContextDefinition tests with exact count assertions and add dependency model test Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../ModelReaderWriterContextDefinition.cs | 14 ++++-- ...ModelReaderWriterContextDefinitionTests.cs | 45 ++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index 9f48e69731f..fe13fd88459 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -113,18 +113,26 @@ private void CollectBuildableTypesRecursive(CSharpType type, HashSet /// private bool ImplementsIPersistableModel(CSharpType type) { - // Check if the type is a model type (not a framework type) + // Check if the type is a framework type (System.* types) if (type.IsFrameworkType) { return false; } - // All generated models implement IPersistableModel + // Check if the type has a model provider in the current library (local models) var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders .OfType() .FirstOrDefault(m => m.Type.Equals(type)); - return modelProvider != null; + if (modelProvider != null) + { + return true; + } + + // For dependency models (models from other libraries), assume they implement IPersistableModel + // if they are not framework types and don't have a model provider in the current library + // This handles models that are referenced from dependency libraries + return !type.IsFrameworkType && !type.IsLiteral && !type.IsEnum && !type.IsGenericTypeDefinition; } protected override XmlDocProvider BuildXmlDocs() diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs index 7c05e842751..4a31135d487 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs @@ -54,9 +54,9 @@ public void ValidateModelReaderWriterBuildableAttributesAreGenerated() Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - // Check that at least one ModelReaderWriterBuildableAttribute exists + // Check that exactly one ModelReaderWriterBuildableAttribute exists since TestModel has only primitive properties var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); - Assert.IsTrue(buildableAttributes.Any(), "At least one ModelReaderWriterBuildableAttribute should be generated"); + Assert.AreEqual(1, buildableAttributes.Count(), "Exactly one ModelReaderWriterBuildableAttribute should be generated for TestModel"); } [Test] @@ -83,9 +83,9 @@ public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - // Check that ModelReaderWriterBuildableAttribute exists for both models + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); - Assert.IsTrue(buildableAttributes.Count() >= 2, "At least two ModelReaderWriterBuildableAttributes should be generated for nested models"); + Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for nested models"); } [Test] @@ -111,9 +111,9 @@ public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperti Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - // Check that ModelReaderWriterBuildableAttribute exists for both models + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); - Assert.IsTrue(buildableAttributes.Count() >= 2, "At least two ModelReaderWriterBuildableAttributes should be generated for collection item models"); + Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for collection item models"); } [Test] @@ -153,5 +153,38 @@ public void ValidateModelReaderWriterBuildableAttributesAvoidDuplicates() Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, "No duplicate ModelReaderWriterBuildableAttributes should be generated"); } + + [Test] + public void ValidateModelReaderWriterBuildableAttributesIncludeDependencyModels() + { + // Create a model with a property that references a model from a dependency library + // The dependency model won't have a model provider in the current library + var dependencyModel = InputFactory.Model("DependencyModel", properties: new[] + { + InputFactory.Property("DependencyValue", InputPrimitiveType.String) + }); + + var parentModel = InputFactory.Model("ParentModel", properties: new[] + { + InputFactory.Property("DependencyProperty", dependencyModel), + InputFactory.Property("SimpleProperty", InputPrimitiveType.String) + }); + + // Only include the parentModel in the mock generator, simulating that + // dependencyModel is from a dependency library + var mockGenerator = MockHelpers.LoadMockGenerator( + inputModels: () => new List { parentModel }); + + var contextDefinition = new ModelReaderWriterContextDefinition(); + var attributes = contextDefinition.Attributes; + + Assert.IsNotNull(attributes); + Assert.IsTrue(attributes.Count > 0); + + // Check that exactly two ModelReaderWriterBuildableAttribute exist: + // one for ParentModel and one for the dependency model + var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); + Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for models with dependency references"); + } } } \ No newline at end of file From b96b301d48a780492949f4aa446b63c6e7455102 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 23:03:37 +0000 Subject: [PATCH 09/21] Fix compilation error by replacing non-existent IsGenericTypeDefinition with IsGenericType Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../src/Providers/ModelReaderWriterContextDefinition.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index fe13fd88459..19b48716e0d 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -130,9 +130,9 @@ private bool ImplementsIPersistableModel(CSharpType type) } // For dependency models (models from other libraries), assume they implement IPersistableModel - // if they are not framework types and don't have a model provider in the current library + // if they are not framework types, not literals, not enums, and not generic types // This handles models that are referenced from dependency libraries - return !type.IsFrameworkType && !type.IsLiteral && !type.IsEnum && !type.IsGenericTypeDefinition; + return !type.IsFrameworkType && !type.IsLiteral && !type.IsEnum && !type.IsGenericType; } protected override XmlDocProvider BuildXmlDocs() From ec49c32ad005428493fa41d2037806fa86132744 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 12:27:36 -0700 Subject: [PATCH 10/21] Fix duplicate handling --- .../ModelReaderWriterContextDefinition.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index 19b48716e0d..3f87f36df38 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -3,6 +3,7 @@ using System; using System.ClientModel.Primitives; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -48,8 +49,8 @@ protected override IReadOnlyList BuildAttributes() /// private HashSet CollectBuildableTypes() { - var buildableTypes = new HashSet(); - var visitedTypes = new HashSet(); + var buildableTypes = new HashSet(new CSharpTypeNameComparer()); + var visitedTypes = new HashSet(new CSharpTypeNameComparer()); // Get all model providers from the output library var modelProviders = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders @@ -162,5 +163,28 @@ private static string RemovePeriods(string input) return buffer.Slice(0, index).ToString(); } + + private class CSharpTypeNameComparer : IEqualityComparer + { + public bool Equals(CSharpType? x, CSharpType? y) + { + if (x is null && y is null) + { + return true; + } + if (x is null || y is null) + { + return false; + } + return x.Namespace == y.Namespace && x.Name == y.Name; + } + + public int GetHashCode(CSharpType obj) + { + HashCode hashCode = new HashCode(); + hashCode.Add(obj.Namespace); + return hashCode.ToHashCode(); + } + } } } From 2da15468a7efbe62b4db6d0d0e21f7582c912375 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 12:56:41 -0700 Subject: [PATCH 11/21] fix script and visitor --- .../eng/scripts/Generate.ps1 | 52 +++++++++---------- .../src/StubLibraryVisitor.cs | 2 +- .../src/Generated/Models/Dog.Serialization.cs | 1 - .../Generated/Models/Snake.Serialization.cs | 1 - .../Generated/Models/Fish.Serialization.cs | 1 - .../Generated/Models/Bird.Serialization.cs | 1 - .../Models/Dinosaur.Serialization.cs | 1 - ...alPropertiesDiscriminated.Serialization.cs | 1 - ...alPropertiesDiscriminated.Serialization.cs | 1 - 9 files changed, 27 insertions(+), 34 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index da645778fd5..778b383dd93 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -15,32 +15,32 @@ if (-not $LaunchOnly) { if ($null -eq $filter -or $filter -eq "Sample-TypeSpec") { - Write-Host "Building logging plugin" -ForegroundColor Cyan - $pluginDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'plugins' 'logging' 'Logging.Plugin' 'src' - Invoke "dotnet build" $pluginDir - - $sampleDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'SampleService' - - Write-Host "Installing SampleTypeSpec plugins" -ForegroundColor Cyan - - Invoke "npm install" $sampleDir - - Write-Host "Generating SampleTypeSpec using plugins" -ForegroundColor Cyan - - Invoke "npx tsp compile . --trace @typespec/http-client-csharp" $sampleDir - - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } - - Write-Host "Building SampleTypeSpec plugin library" -ForegroundColor Cyan - Invoke "dotnet build $sampleDir/SampleClient/src/SampleTypeSpec.csproj" - - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } +# Write-Host "Building logging plugin" -ForegroundColor Cyan +# $pluginDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'plugins' 'logging' 'Logging.Plugin' 'src' +# Invoke "dotnet build" $pluginDir +# +# $sampleDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'SampleService' +# +# Write-Host "Installing SampleTypeSpec plugins" -ForegroundColor Cyan +# +# Invoke "npm install" $sampleDir +# +# Write-Host "Generating SampleTypeSpec using plugins" -ForegroundColor Cyan +# +# Invoke "npx tsp compile . --trace @typespec/http-client-csharp" $sampleDir +# +# # exit if the generation failed +# if ($LASTEXITCODE -ne 0) { +# exit $LASTEXITCODE +# } +# +# Write-Host "Building SampleTypeSpec plugin library" -ForegroundColor Cyan +# Invoke "dotnet build $sampleDir/SampleClient/src/SampleTypeSpec.csproj" +# +# # exit if the generation failed +# if ($LASTEXITCODE -ne 0) { +# exit $LASTEXITCODE +# } Write-Host "Generating SampleTypeSpec" -ForegroundColor Cyan $testProjectsLocalDir = Join-Path $packageRoot 'generator' 'TestProjects' 'Local' diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs index 6f9c29c6542..5a91e7d7964 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs @@ -23,7 +23,7 @@ internal class StubLibraryVisitor : ScmLibraryVisitor !type.Name.Equals("MultiPartFormDataBinaryContent", StringComparison.Ordinal)) return null; - type.Update(xmlDocs: XmlDocProvider.Empty); + type.Update(xmlDocs: XmlDocProvider.Empty, attributes: []); return type; } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs index f56d5d5949f..e298c7c2fe0 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Model.Inheritance.EnumDiscriminator { - [PersistableModelProxy(typeof(UnknownDog))] public abstract partial class Dog : IJsonModel { internal Dog() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs index b94feb2a34e..bac1a22763e 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Model.Inheritance.EnumDiscriminator { - [PersistableModelProxy(typeof(UnknownSnake))] public abstract partial class Snake : IJsonModel { internal Snake() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs index 815c2485173..2b994e540d0 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Model.Inheritance.NestedDiscriminator { - [PersistableModelProxy(typeof(UnknownFish))] public abstract partial class Fish : IJsonModel { internal Fish() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs index 46c4f020cb3..ae72b55131f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Model.Inheritance.SingleDiscriminator { - [PersistableModelProxy(typeof(UnknownBird))] public abstract partial class Bird : IJsonModel { internal Bird() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs index 8b16e7d19e6..9cec6ff7173 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Model.Inheritance.SingleDiscriminator { - [PersistableModelProxy(typeof(UnknownDinosaur))] public abstract partial class Dinosaur : IJsonModel { internal Dinosaur() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs index f7e9f72a561..46390968f81 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Property.AdditionalProperties { - [PersistableModelProxy(typeof(UnknownExtendsUnknownAdditionalPropertiesDiscriminated))] public abstract partial class ExtendsUnknownAdditionalPropertiesDiscriminated : IJsonModel { internal ExtendsUnknownAdditionalPropertiesDiscriminated() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs index 3a7409587b3..63f64af1537 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs @@ -9,7 +9,6 @@ namespace _Type.Property.AdditionalProperties { - [PersistableModelProxy(typeof(UnknownIsUnknownAdditionalPropertiesDiscriminated))] public abstract partial class IsUnknownAdditionalPropertiesDiscriminated : IJsonModel { internal IsUnknownAdditionalPropertiesDiscriminated() => throw null; From b784c2a6093422b924dda6f462016cd4784646b0 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 13:23:52 -0700 Subject: [PATCH 12/21] remove invalid attributes --- .../src/PostProcessing/PostProcessor.cs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs index 5af938ece5c..657a13a4265 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs @@ -359,6 +359,123 @@ private async Task RemoveModelsAsync(Project project, // remove what are now invalid usings due to the models being removed project = await RemoveInvalidUsings(project); + // remove invalid attributes from the MRWContext attributes + project = await RemoveInvalidAttributesFromMrwContextAsync(project); + + return project; + } + + private async Task RemoveInvalidAttributesFromMrwContextAsync(Project project) + { + var compilation = await project.GetCompilationAsync(); + if (compilation == null) + return project; + + // Find the MRWContext class + foreach (var document in project.Documents) + { + var root = await document.GetSyntaxRootAsync(); + if (root == null) + continue; + + var semanticModel = compilation.GetSemanticModel(root.SyntaxTree); + + // Find all class declarations that inherit from ModelReaderWriterContext + var mrwContextClasses = root.DescendantNodes() + .OfType() + .Where(c => c.BaseList != null && + c.BaseList.Types.Any(t => + { + var baseTypeSymbol = semanticModel.GetSymbolInfo(t.Type).Symbol as INamedTypeSymbol; + return baseTypeSymbol?.Name == "ModelReaderWriterContext"; + })) + .ToList(); + + if (!mrwContextClasses.Any()) + continue; + + // Process each MRWContext class + var newRoot = root; + foreach (var mrwContextClass in mrwContextClasses) + { + // Get all attributes on the class + var attributesToRemove = new List(); + + foreach (var attributeList in mrwContextClass.AttributeLists) + { + foreach (var attribute in attributeList.Attributes) + { + var attributeSymbol = semanticModel.GetSymbolInfo(attribute).Symbol; + if (attributeSymbol == null) + { + // If we can't resolve the attribute symbol, it might be pointing to a removed type + attributesToRemove.Add(attribute); + continue; + } + + // Check if the attribute has any arguments that reference types + if (attribute.ArgumentList != null) + { + foreach (var arg in attribute.ArgumentList.Arguments) + { + if (arg.Expression is TypeOfExpressionSyntax typeOfExpr) + { + var typeSymbol = semanticModel.GetSymbolInfo(typeOfExpr.Type).Symbol; + if (typeSymbol == null) + { + // The type referenced in typeof() no longer exists + attributesToRemove.Add(attribute); + break; + } + } + } + } + } + } + + // Remove invalid attributes + if (attributesToRemove.Any()) + { + var updatedClass = mrwContextClass; + + // Group attributes by their containing AttributeList + var attributeListsToUpdate = attributesToRemove + .GroupBy(attr => attr.Parent as AttributeListSyntax) + .Where(g => g.Key != null); + + foreach (var group in attributeListsToUpdate) + { + var attributeList = group.Key!; + var remainingAttributes = attributeList.Attributes + .Where(a => !group.Contains(a)) + .ToList(); + + if (remainingAttributes.Any()) + { + // Update the attribute list with remaining attributes + var newAttributeList = attributeList.WithAttributes( + SyntaxFactory.SeparatedList(remainingAttributes)); + updatedClass = updatedClass.ReplaceNode(attributeList, newAttributeList); + } + else + { + // Remove the entire attribute list if no attributes remain + var attributeLists = updatedClass.AttributeLists.Remove(attributeList); + updatedClass = updatedClass.WithAttributeLists(attributeLists); + } + } + + newRoot = newRoot.ReplaceNode(mrwContextClass, updatedClass); + } + } + + if (newRoot != root) + { + var newDocument = document.WithSyntaxRoot(newRoot); + project = newDocument.Project; + } + } + return project; } From f59e15a1d3ad9e11bacb594194ff0072244cb3b7 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 18:01:18 -0700 Subject: [PATCH 13/21] working --- .../src/PostProcessing/PostProcessor.cs | 78 ++++++++++--------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs index 657a13a4265..d0298cee5db 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs @@ -341,6 +341,7 @@ private async Task RemoveModelsAsync(Project project, { // accumulate the definitions from the same document together var documents = new Dictionary>(); + foreach (var model in unusedModels) { var document = project.GetDocument(model.SyntaxTree); @@ -371,7 +372,6 @@ private async Task RemoveInvalidAttributesFromMrwContextAsync(Project p if (compilation == null) return project; - // Find the MRWContext class foreach (var document in project.Documents) { var root = await document.GetSyntaxRootAsync(); @@ -391,10 +391,12 @@ private async Task RemoveInvalidAttributesFromMrwContextAsync(Project p })) .ToList(); - if (!mrwContextClasses.Any()) + if (mrwContextClasses.Count == 0) + { continue; + } - // Process each MRWContext class + // Process each MrwContext class var newRoot = root; foreach (var mrwContextClass in mrwContextClasses) { @@ -405,13 +407,7 @@ private async Task RemoveInvalidAttributesFromMrwContextAsync(Project p { foreach (var attribute in attributeList.Attributes) { - var attributeSymbol = semanticModel.GetSymbolInfo(attribute).Symbol; - if (attributeSymbol == null) - { - // If we can't resolve the attribute symbol, it might be pointing to a removed type - attributesToRemove.Add(attribute); - continue; - } + bool shouldRemove = false; // Check if the attribute has any arguments that reference types if (attribute.ArgumentList != null) @@ -420,52 +416,53 @@ private async Task RemoveInvalidAttributesFromMrwContextAsync(Project p { if (arg.Expression is TypeOfExpressionSyntax typeOfExpr) { - var typeSymbol = semanticModel.GetSymbolInfo(typeOfExpr.Type).Symbol; - if (typeSymbol == null) + var typeInfo = semanticModel.GetTypeInfo(typeOfExpr.Type); + // Check if this is an error type (unresolved) + if (typeInfo.Type?.TypeKind == TypeKind.Error) { - // The type referenced in typeof() no longer exists - attributesToRemove.Add(attribute); + shouldRemove = true; break; } } } } + + if (shouldRemove) + { + attributesToRemove.Add(attribute); + } } } // Remove invalid attributes - if (attributesToRemove.Any()) + if (attributesToRemove.Count > 0) { - var updatedClass = mrwContextClass; - - // Group attributes by their containing AttributeList - var attributeListsToUpdate = attributesToRemove - .GroupBy(attr => attr.Parent as AttributeListSyntax) - .Where(g => g.Key != null); - - foreach (var group in attributeListsToUpdate) + // Find the current version of the class in the newRoot + var currentClass = newRoot.DescendantNodes() + .OfType() + .First(c => c.Identifier.Text == mrwContextClass.Identifier.Text); + + // Create new attribute lists by filtering out the attributes to remove + var newAttributeLists = new List(); + foreach (var attributeList in currentClass.AttributeLists) { - var attributeList = group.Key!; var remainingAttributes = attributeList.Attributes - .Where(a => !group.Contains(a)) + .Where(attr => attributesToRemove.All(toRemove => toRemove.Span != attr.Span)) .ToList(); - if (remainingAttributes.Any()) + if (remainingAttributes.Count > 0) { - // Update the attribute list with remaining attributes var newAttributeList = attributeList.WithAttributes( SyntaxFactory.SeparatedList(remainingAttributes)); - updatedClass = updatedClass.ReplaceNode(attributeList, newAttributeList); - } - else - { - // Remove the entire attribute list if no attributes remain - var attributeLists = updatedClass.AttributeLists.Remove(attributeList); - updatedClass = updatedClass.WithAttributeLists(attributeLists); + newAttributeLists.Add(newAttributeList); } } - newRoot = newRoot.ReplaceNode(mrwContextClass, updatedClass); + // Create updated class with new attribute lists + var updatedClass = currentClass.WithAttributeLists(SyntaxFactory.List(newAttributeLists)); + + // Replace in the root + newRoot = newRoot.ReplaceNode(currentClass, updatedClass); } } @@ -479,6 +476,17 @@ private async Task RemoveInvalidAttributesFromMrwContextAsync(Project p return project; } + private static string GetTypeNameFromTypeSyntax(TypeSyntax typeSyntax) + { + return typeSyntax switch + { + IdentifierNameSyntax identifierName => identifierName.Identifier.Text, + QualifiedNameSyntax qualifiedName => GetTypeNameFromTypeSyntax(qualifiedName.Right), + GenericNameSyntax genericName => genericName.Identifier.Text, + _ => string.Empty + }; + } + private static BaseTypeDeclarationSyntax ChangeModifier(BaseTypeDeclarationSyntax memberDeclaration, SyntaxKind from, SyntaxKind to) From c36c26c39f683debfc7373bc09a0df9e700c5c39 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 19:36:31 -0700 Subject: [PATCH 14/21] fix --- .../eng/scripts/Generate.ps1 | 18 +- .../ModelReaderWriterContextDefinition.cs | 1 - .../src/PostProcessing/PostProcessor.cs | 209 +++++------------- 3 files changed, 70 insertions(+), 158 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index 778b383dd93..5daa5f994e6 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -15,15 +15,15 @@ if (-not $LaunchOnly) { if ($null -eq $filter -or $filter -eq "Sample-TypeSpec") { -# Write-Host "Building logging plugin" -ForegroundColor Cyan -# $pluginDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'plugins' 'logging' 'Logging.Plugin' 'src' -# Invoke "dotnet build" $pluginDir -# -# $sampleDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'SampleService' -# -# Write-Host "Installing SampleTypeSpec plugins" -ForegroundColor Cyan -# -# Invoke "npm install" $sampleDir + Write-Host "Building logging plugin" -ForegroundColor Cyan + $pluginDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'plugins' 'logging' 'Logging.Plugin' 'src' + Invoke "dotnet build" $pluginDir + + $sampleDir = Join-Path $packageRoot '..' '..' 'docs' 'samples' 'client' 'csharp' 'SampleService' + + Write-Host "Installing SampleTypeSpec plugins" -ForegroundColor Cyan + + Invoke "npm install" $sampleDir # # Write-Host "Generating SampleTypeSpec using plugins" -ForegroundColor Cyan # diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index 3f87f36df38..a4024ab7995 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -3,7 +3,6 @@ using System; using System.ClientModel.Primitives; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs index d0298cee5db..f6fb6feefe8 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs @@ -357,136 +357,12 @@ private async Task RemoveModelsAsync(Project project, project = await RemoveModelsFromDocumentAsync(project, models); } - // remove what are now invalid usings due to the models being removed - project = await RemoveInvalidUsings(project); - - // remove invalid attributes from the MRWContext attributes - project = await RemoveInvalidAttributesFromMrwContextAsync(project); - - return project; - } - - private async Task RemoveInvalidAttributesFromMrwContextAsync(Project project) - { - var compilation = await project.GetCompilationAsync(); - if (compilation == null) - return project; - - foreach (var document in project.Documents) - { - var root = await document.GetSyntaxRootAsync(); - if (root == null) - continue; - - var semanticModel = compilation.GetSemanticModel(root.SyntaxTree); - - // Find all class declarations that inherit from ModelReaderWriterContext - var mrwContextClasses = root.DescendantNodes() - .OfType() - .Where(c => c.BaseList != null && - c.BaseList.Types.Any(t => - { - var baseTypeSymbol = semanticModel.GetSymbolInfo(t.Type).Symbol as INamedTypeSymbol; - return baseTypeSymbol?.Name == "ModelReaderWriterContext"; - })) - .ToList(); - - if (mrwContextClasses.Count == 0) - { - continue; - } - - // Process each MrwContext class - var newRoot = root; - foreach (var mrwContextClass in mrwContextClasses) - { - // Get all attributes on the class - var attributesToRemove = new List(); - - foreach (var attributeList in mrwContextClass.AttributeLists) - { - foreach (var attribute in attributeList.Attributes) - { - bool shouldRemove = false; - - // Check if the attribute has any arguments that reference types - if (attribute.ArgumentList != null) - { - foreach (var arg in attribute.ArgumentList.Arguments) - { - if (arg.Expression is TypeOfExpressionSyntax typeOfExpr) - { - var typeInfo = semanticModel.GetTypeInfo(typeOfExpr.Type); - // Check if this is an error type (unresolved) - if (typeInfo.Type?.TypeKind == TypeKind.Error) - { - shouldRemove = true; - break; - } - } - } - } - - if (shouldRemove) - { - attributesToRemove.Add(attribute); - } - } - } - - // Remove invalid attributes - if (attributesToRemove.Count > 0) - { - // Find the current version of the class in the newRoot - var currentClass = newRoot.DescendantNodes() - .OfType() - .First(c => c.Identifier.Text == mrwContextClass.Identifier.Text); - - // Create new attribute lists by filtering out the attributes to remove - var newAttributeLists = new List(); - foreach (var attributeList in currentClass.AttributeLists) - { - var remainingAttributes = attributeList.Attributes - .Where(attr => attributesToRemove.All(toRemove => toRemove.Span != attr.Span)) - .ToList(); - - if (remainingAttributes.Count > 0) - { - var newAttributeList = attributeList.WithAttributes( - SyntaxFactory.SeparatedList(remainingAttributes)); - newAttributeLists.Add(newAttributeList); - } - } - - // Create updated class with new attribute lists - var updatedClass = currentClass.WithAttributeLists(SyntaxFactory.List(newAttributeLists)); - - // Replace in the root - newRoot = newRoot.ReplaceNode(currentClass, updatedClass); - } - } - - if (newRoot != root) - { - var newDocument = document.WithSyntaxRoot(newRoot); - project = newDocument.Project; - } - } + // remove what are now invalid references due to the models being removed + project = await RemoveInvalidRefs(project); return project; } - private static string GetTypeNameFromTypeSyntax(TypeSyntax typeSyntax) - { - return typeSyntax switch - { - IdentifierNameSyntax identifierName => identifierName.Identifier.Text, - QualifiedNameSyntax qualifiedName => GetTypeNameFromTypeSyntax(qualifiedName.Right), - GenericNameSyntax genericName => genericName.Identifier.Text, - _ => string.Empty - }; - } - private static BaseTypeDeclarationSyntax ChangeModifier(BaseTypeDeclarationSyntax memberDeclaration, SyntaxKind from, SyntaxKind to) @@ -528,39 +404,76 @@ private async Task RemoveModelsFromDocumentAsync(Project project, return document.Project; } - private async Task RemoveInvalidUsings(Project project) + private async Task RemoveInvalidRefs(Project project) { var solution = project.Solution; + + // Process each document for invalid usings foreach (var documentId in project.DocumentIds) { - var document = solution.GetDocument(documentId)!; - var root = await document.GetSyntaxRootAsync(); - var model = await document.GetSemanticModelAsync(); + solution = await RemoveInvalidUsings(solution, documentId); + } - if (root is not CompilationUnitSyntax cu || model == null) - { - continue; - } + // Process each document for invalid attributes (with fresh semantic models) + foreach (var documentId in project.DocumentIds) + { + solution = await RemoveInvalidAttributes(solution, documentId); + } - var invalidUsings = cu.Usings - .Where(u => - { - var info = model.GetSymbolInfo(u.Name!); - var sym = info.Symbol; - return sym is null || sym.Kind != SymbolKind.Namespace; - }) - .ToList(); + return solution.GetProject(project.Id)!; + } + + private async Task RemoveInvalidUsings(Solution solution, DocumentId documentId) + { + var document = solution.GetDocument(documentId)!; + var root = await document.GetSyntaxRootAsync(); + var model = await document.GetSemanticModelAsync(); + + if (root is not CompilationUnitSyntax cu || model == null) + return solution; - if (invalidUsings.Count == 0) + var invalidUsings = cu.Usings + .Where(u => { - continue; - } + var info = model.GetSymbolInfo(u.Name!); + var sym = info.Symbol; + return sym is null || sym.Kind != SymbolKind.Namespace; + }) + .ToList(); - var cleaned = cu.RemoveNodes(invalidUsings, SyntaxRemoveOptions.KeepNoTrivia); - solution = solution.WithDocumentSyntaxRoot(documentId, cleaned!); + if (invalidUsings.Count > 0) + { + cu = cu.RemoveNodes(invalidUsings, SyntaxRemoveOptions.KeepNoTrivia)!; + solution = solution.WithDocumentSyntaxRoot(documentId, cu); } - return solution.GetProject(project.Id)!; + return solution; + } + + private async Task RemoveInvalidAttributes(Solution solution, DocumentId documentId) + { + var document = solution.GetDocument(documentId)!; + var root = await document.GetSyntaxRootAsync(); + var model = await document.GetSemanticModelAsync(); + + if (root is not CompilationUnitSyntax cu || model == null) + return solution; + + var invalidAttributes = cu.DescendantNodes() + .OfType() + .Where(attr => attr.Attributes.Any(attribute => + attribute.ArgumentList?.Arguments.Any(arg => + arg.Expression is TypeOfExpressionSyntax typeOfExpr && + model.GetTypeInfo(typeOfExpr.Type).Type?.TypeKind == TypeKind.Error) == true)) + .ToList(); + + if (invalidAttributes.Count > 0) + { + cu = cu.RemoveNodes(invalidAttributes, SyntaxRemoveOptions.KeepNoTrivia)!; + solution = solution.WithDocumentSyntaxRoot(documentId, cu); + } + + return solution; } private async Task> GetRootSymbolsAsync(Project project, TypeSymbols modelSymbols) From 861e8423d2651d52422def7e1625305c87489964 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 16 Jul 2025 20:01:25 -0700 Subject: [PATCH 15/21] force deps --- .../eng/scripts/Generate.ps1 | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index 5daa5f994e6..1e9579a0196 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -23,24 +23,24 @@ if (-not $LaunchOnly) { Write-Host "Installing SampleTypeSpec plugins" -ForegroundColor Cyan - Invoke "npm install" $sampleDir -# -# Write-Host "Generating SampleTypeSpec using plugins" -ForegroundColor Cyan -# -# Invoke "npx tsp compile . --trace @typespec/http-client-csharp" $sampleDir -# -# # exit if the generation failed -# if ($LASTEXITCODE -ne 0) { -# exit $LASTEXITCODE -# } -# -# Write-Host "Building SampleTypeSpec plugin library" -ForegroundColor Cyan -# Invoke "dotnet build $sampleDir/SampleClient/src/SampleTypeSpec.csproj" -# -# # exit if the generation failed -# if ($LASTEXITCODE -ne 0) { -# exit $LASTEXITCODE -# } + Invoke "npm install --force" $sampleDir + + Write-Host "Generating SampleTypeSpec using plugins" -ForegroundColor Cyan + + Invoke "npx tsp compile . --trace @typespec/http-client-csharp" $sampleDir + + # exit if the generation failed + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } + + Write-Host "Building SampleTypeSpec plugin library" -ForegroundColor Cyan + Invoke "dotnet build $sampleDir/SampleClient/src/SampleTypeSpec.csproj" + + # exit if the generation failed + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } Write-Host "Generating SampleTypeSpec" -ForegroundColor Cyan $testProjectsLocalDir = Join-Path $packageRoot 'generator' 'TestProjects' 'Local' From 8f5dd17888129dd2d9cc86eadb3f83f47c08ce06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Jul 2025 06:19:57 +0000 Subject: [PATCH 16/21] Fix TypeOfExpression to ensure proper using statements are generated Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com> --- .../src/Expressions/TypeOfExpression.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs index 83251dee1c3..baaf22a9c6b 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs @@ -9,6 +9,11 @@ public record TypeOfExpression(CSharpType Type) : ValueExpression { internal override void Write(CodeWriter writer) { + // Explicitly ensure the namespace is added to the using statements + if (!string.IsNullOrEmpty(Type.Namespace)) + { + writer.UseNamespace(Type.Namespace); + } writer.Append($"typeof({Type})"); } } From e87c0ba085a85ce7a3a2c727e52b5ec01c09df79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:37:23 +0000 Subject: [PATCH 17/21] Revert TypeOfExpression.cs changes as requested Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> --- .../src/Expressions/TypeOfExpression.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs index baaf22a9c6b..83251dee1c3 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Expressions/TypeOfExpression.cs @@ -9,11 +9,6 @@ public record TypeOfExpression(CSharpType Type) : ValueExpression { internal override void Write(CodeWriter writer) { - // Explicitly ensure the namespace is added to the using statements - if (!string.IsNullOrEmpty(Type.Namespace)) - { - writer.UseNamespace(Type.Namespace); - } writer.Append($"typeof({Type})"); } } From 5e7871767e00b4cccadc943bef168e2ef138d19a Mon Sep 17 00:00:00 2001 From: jolov Date: Thu, 17 Jul 2025 19:12:50 -0700 Subject: [PATCH 18/21] regen --- .../src/StubLibraryVisitor.cs | 2 +- .../Generated/Models/EncodeBytesContext.cs | 4 ++ .../Generated/Models/EncodeDatetimeContext.cs | 5 +++ .../Generated/Models/EncodeDurationContext.cs | 7 ++++ .../Generated/Models/EncodeNumericContext.cs | 4 ++ .../Models/ParametersBasicContext.cs | 3 ++ .../ParametersBodyOptionalityContext.cs | 1 + .../Models/ParametersSpreadContext.cs | 3 ++ .../PayloadContentNegotiationContext.cs | 2 + .../Models/PayloadJsonMergePatchContext.cs | 2 + .../Models/PayloadMultiPartContext.cs | 2 + .../Models/PayloadPageableContext.cs | 3 ++ .../Models/ResponseStatusCodeRangeContext.cs | 2 + .../SerializationEncodedNameJsonContext.cs | 2 + .../Generated/Models/SpecialWordsContext.cs | 36 +++++++++++++++++ .../Generated/Models/_Type_ArrayContext.cs | 1 + .../Models/_TypeDictionaryContext.cs | 1 + .../Models/_TypeModelEmptyContext.cs | 3 ++ .../src/Generated/Models/Dog.Serialization.cs | 1 + .../Generated/Models/Snake.Serialization.cs | 1 + ...odelInheritanceEnumDiscriminatorContext.cs | 6 +++ .../Generated/Models/Fish.Serialization.cs | 1 + ...elInheritanceNestedDiscriminatorContext.cs | 7 ++++ ...ModelInheritanceNotDiscriminatedContext.cs | 3 ++ .../_TypeModelInheritanceRecursiveContext.cs | 2 + .../Generated/Models/Bird.Serialization.cs | 1 + .../Models/Dinosaur.Serialization.cs | 1 + ...elInheritanceSingleDiscriminatorContext.cs | 9 +++++ .../Models/_TypeModelUsageContext.cs | 3 ++ .../Models/_TypeModelVisibilityContext.cs | 2 + ...alPropertiesDiscriminated.Serialization.cs | 1 + ...alPropertiesDiscriminated.Serialization.cs | 1 + ...TypePropertyAdditionalPropertiesContext.cs | 39 +++++++++++++++++++ .../Models/_TypePropertyNullableContext.cs | 8 ++++ .../Models/_TypePropertyOptionalContext.cs | 16 ++++++++ .../Models/_TypePropertyValueTypesContext.cs | 30 ++++++++++++++ .../src/Generated/Models/_TypeUnionContext.cs | 16 ++++++++ .../Models/VersioningAddedV1Context.cs | 2 + .../Models/VersioningAddedV2Context.cs | 3 ++ .../Models/VersioningMadeOptionalV1Context.cs | 2 + .../Models/VersioningMadeOptionalV2Context.cs | 2 + .../Models/VersioningRemovedV1Context.cs | 4 ++ .../Models/VersioningRemovedV2Context.cs | 3 ++ .../VersioningRemovedV2PreviewContext.cs | 4 ++ .../Models/VersioningRenamedFromV1Context.cs | 2 + .../Models/VersioningRenamedFromV2Context.cs | 2 + .../VersioningTypeChangedFromV1Context.cs | 2 + .../VersioningTypeChangedFromV2Context.cs | 2 + 48 files changed, 258 insertions(+), 1 deletion(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs index 5a91e7d7964..6f9c29c6542 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs @@ -23,7 +23,7 @@ internal class StubLibraryVisitor : ScmLibraryVisitor !type.Name.Equals("MultiPartFormDataBinaryContent", StringComparison.Ordinal)) return null; - type.Update(xmlDocs: XmlDocProvider.Empty, attributes: []); + type.Update(xmlDocs: XmlDocProvider.Empty); return type; } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/src/Generated/Models/EncodeBytesContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/src/Generated/Models/EncodeBytesContext.cs index 80a42ebc50d..5c0cbde8e8f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/src/Generated/Models/EncodeBytesContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/src/Generated/Models/EncodeBytesContext.cs @@ -6,6 +6,10 @@ namespace Encode.Bytes { + [ModelReaderWriterBuildable(typeof(DefaultBytesProperty))] + [ModelReaderWriterBuildable(typeof(Base64BytesProperty))] + [ModelReaderWriterBuildable(typeof(Base64urlBytesProperty))] + [ModelReaderWriterBuildable(typeof(Base64urlArrayBytesProperty))] public partial class EncodeBytesContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/src/Generated/Models/EncodeDatetimeContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/src/Generated/Models/EncodeDatetimeContext.cs index bfeadd55559..07b40150f83 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/src/Generated/Models/EncodeDatetimeContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/src/Generated/Models/EncodeDatetimeContext.cs @@ -6,6 +6,11 @@ namespace Encode.Datetime { + [ModelReaderWriterBuildable(typeof(DefaultDatetimeProperty))] + [ModelReaderWriterBuildable(typeof(Rfc3339DatetimeProperty))] + [ModelReaderWriterBuildable(typeof(Rfc7231DatetimeProperty))] + [ModelReaderWriterBuildable(typeof(UnixTimestampDatetimeProperty))] + [ModelReaderWriterBuildable(typeof(UnixTimestampArrayDatetimeProperty))] public partial class EncodeDatetimeContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/src/Generated/Models/EncodeDurationContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/src/Generated/Models/EncodeDurationContext.cs index 1064af3f756..0c46dd17e91 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/src/Generated/Models/EncodeDurationContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/src/Generated/Models/EncodeDurationContext.cs @@ -3,9 +3,16 @@ #nullable disable using System.ClientModel.Primitives; +using Encode.Duration._Property; namespace Encode.Duration { + [ModelReaderWriterBuildable(typeof(DefaultDurationProperty))] + [ModelReaderWriterBuildable(typeof(ISO8601DurationProperty))] + [ModelReaderWriterBuildable(typeof(Int32SecondsDurationProperty))] + [ModelReaderWriterBuildable(typeof(FloatSecondsDurationProperty))] + [ModelReaderWriterBuildable(typeof(Float64SecondsDurationProperty))] + [ModelReaderWriterBuildable(typeof(FloatSecondsDurationArrayProperty))] public partial class EncodeDurationContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/src/Generated/Models/EncodeNumericContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/src/Generated/Models/EncodeNumericContext.cs index 52b86801187..bc0cafbf1a3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/src/Generated/Models/EncodeNumericContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/src/Generated/Models/EncodeNumericContext.cs @@ -3,9 +3,13 @@ #nullable disable using System.ClientModel.Primitives; +using Encode.Numeric._Property; namespace Encode.Numeric { + [ModelReaderWriterBuildable(typeof(SafeintAsStringProperty))] + [ModelReaderWriterBuildable(typeof(Uint32AsStringProperty))] + [ModelReaderWriterBuildable(typeof(Uint8AsStringProperty))] public partial class EncodeNumericContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/src/Generated/Models/ParametersBasicContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/src/Generated/Models/ParametersBasicContext.cs index 527011575a7..d21f56d38b7 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/src/Generated/Models/ParametersBasicContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/src/Generated/Models/ParametersBasicContext.cs @@ -3,9 +3,12 @@ #nullable disable using System.ClientModel.Primitives; +using Parameters.Basic._ExplicitBody; +using Parameters.Basic._ImplicitBody; namespace Parameters.Basic { + [ModelReaderWriterBuildable(typeof(User))] public partial class ParametersBasicContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/src/Generated/Models/ParametersBodyOptionalityContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/src/Generated/Models/ParametersBodyOptionalityContext.cs index 072b422217b..cf75f43d92f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/src/Generated/Models/ParametersBodyOptionalityContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/src/Generated/Models/ParametersBodyOptionalityContext.cs @@ -6,6 +6,7 @@ namespace Parameters.BodyOptionality { + [ModelReaderWriterBuildable(typeof(BodyModel))] public partial class ParametersBodyOptionalityContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/src/Generated/Models/ParametersSpreadContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/src/Generated/Models/ParametersSpreadContext.cs index 9730bb9899e..fca7b7b5ee9 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/src/Generated/Models/ParametersSpreadContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/src/Generated/Models/ParametersSpreadContext.cs @@ -3,9 +3,12 @@ #nullable disable using System.ClientModel.Primitives; +using Parameters.Spread._Alias; +using Parameters.Spread._Model; namespace Parameters.Spread { + [ModelReaderWriterBuildable(typeof(BodyParameter))] public partial class ParametersSpreadContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/content-negotiation/src/Generated/Models/PayloadContentNegotiationContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/content-negotiation/src/Generated/Models/PayloadContentNegotiationContext.cs index 9f5c2258980..adc8d9a36c0 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/content-negotiation/src/Generated/Models/PayloadContentNegotiationContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/content-negotiation/src/Generated/Models/PayloadContentNegotiationContext.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Payload.ContentNegotiation._DifferentBody; namespace Payload.ContentNegotiation { + [ModelReaderWriterBuildable(typeof(PngImageAsJson))] public partial class PayloadContentNegotiationContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/src/Generated/Models/PayloadJsonMergePatchContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/src/Generated/Models/PayloadJsonMergePatchContext.cs index 0f0894f4373..65f36a74d66 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/src/Generated/Models/PayloadJsonMergePatchContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/src/Generated/Models/PayloadJsonMergePatchContext.cs @@ -6,6 +6,8 @@ namespace Payload.JsonMergePatch { + [ModelReaderWriterBuildable(typeof(Resource))] + [ModelReaderWriterBuildable(typeof(InnerModel))] public partial class PayloadJsonMergePatchContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs index 3ea74bcd753..390c801869d 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs @@ -3,6 +3,8 @@ #nullable disable using System.ClientModel.Primitives; +using Payload.MultiPart._FormData; +using Payload.MultiPart._FormData.HttpParts.NonString; namespace Payload.MultiPart { diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/src/Generated/Models/PayloadPageableContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/src/Generated/Models/PayloadPageableContext.cs index d8287a37a8f..32cea242338 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/src/Generated/Models/PayloadPageableContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/src/Generated/Models/PayloadPageableContext.cs @@ -3,9 +3,12 @@ #nullable disable using System.ClientModel.Primitives; +using Payload.Pageable._ServerDrivenPagination; +using Payload.Pageable._ServerDrivenPagination.ContinuationToken; namespace Payload.Pageable { + [ModelReaderWriterBuildable(typeof(Pet))] public partial class PayloadPageableContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/response/status-code-range/src/Generated/Models/ResponseStatusCodeRangeContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/response/status-code-range/src/Generated/Models/ResponseStatusCodeRangeContext.cs index 1b96d6be611..246085379b8 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/response/status-code-range/src/Generated/Models/ResponseStatusCodeRangeContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/response/status-code-range/src/Generated/Models/ResponseStatusCodeRangeContext.cs @@ -6,6 +6,8 @@ namespace Response.StatusCodeRange { + [ModelReaderWriterBuildable(typeof(ErrorInRange))] + [ModelReaderWriterBuildable(typeof(NotFoundError))] public partial class ResponseStatusCodeRangeContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/src/Generated/Models/SerializationEncodedNameJsonContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/src/Generated/Models/SerializationEncodedNameJsonContext.cs index 5a3fdea8f4c..90ff61856f4 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/src/Generated/Models/SerializationEncodedNameJsonContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/src/Generated/Models/SerializationEncodedNameJsonContext.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Serialization.EncodedName.Json._Property; namespace Serialization.EncodedName.Json { + [ModelReaderWriterBuildable(typeof(JsonEncodedNameModel))] public partial class SerializationEncodedNameJsonContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/src/Generated/Models/SpecialWordsContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/src/Generated/Models/SpecialWordsContext.cs index 27b77157b7f..62b7b62a1d5 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/src/Generated/Models/SpecialWordsContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/src/Generated/Models/SpecialWordsContext.cs @@ -3,9 +3,45 @@ #nullable disable using System.ClientModel.Primitives; +using SpecialWords._ModelProperties; +using SpecialWords._Models; namespace SpecialWords { + [ModelReaderWriterBuildable(typeof(And))] + [ModelReaderWriterBuildable(typeof(As))] + [ModelReaderWriterBuildable(typeof(Assert))] + [ModelReaderWriterBuildable(typeof(Async))] + [ModelReaderWriterBuildable(typeof(Await))] + [ModelReaderWriterBuildable(typeof(Break))] + [ModelReaderWriterBuildable(typeof(Class))] + [ModelReaderWriterBuildable(typeof(Constructor))] + [ModelReaderWriterBuildable(typeof(Continue))] + [ModelReaderWriterBuildable(typeof(Def))] + [ModelReaderWriterBuildable(typeof(Del))] + [ModelReaderWriterBuildable(typeof(Elif))] + [ModelReaderWriterBuildable(typeof(Else))] + [ModelReaderWriterBuildable(typeof(Except))] + [ModelReaderWriterBuildable(typeof(Exec))] + [ModelReaderWriterBuildable(typeof(Finally))] + [ModelReaderWriterBuildable(typeof(For))] + [ModelReaderWriterBuildable(typeof(From))] + [ModelReaderWriterBuildable(typeof(Global))] + [ModelReaderWriterBuildable(typeof(If))] + [ModelReaderWriterBuildable(typeof(Import))] + [ModelReaderWriterBuildable(typeof(In))] + [ModelReaderWriterBuildable(typeof(Is))] + [ModelReaderWriterBuildable(typeof(Lambda))] + [ModelReaderWriterBuildable(typeof(Not))] + [ModelReaderWriterBuildable(typeof(Or))] + [ModelReaderWriterBuildable(typeof(Pass))] + [ModelReaderWriterBuildable(typeof(Raise))] + [ModelReaderWriterBuildable(typeof(Return))] + [ModelReaderWriterBuildable(typeof(Try))] + [ModelReaderWriterBuildable(typeof(While))] + [ModelReaderWriterBuildable(typeof(With))] + [ModelReaderWriterBuildable(typeof(Yield))] + [ModelReaderWriterBuildable(typeof(SameAsModel))] public partial class SpecialWordsContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/src/Generated/Models/_Type_ArrayContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/src/Generated/Models/_Type_ArrayContext.cs index 0407f0c9b77..a06d0a8ec92 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/src/Generated/Models/_Type_ArrayContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/src/Generated/Models/_Type_ArrayContext.cs @@ -6,6 +6,7 @@ namespace _Type._Array { + [ModelReaderWriterBuildable(typeof(InnerModel))] public partial class _Type_ArrayContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/src/Generated/Models/_TypeDictionaryContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/src/Generated/Models/_TypeDictionaryContext.cs index 31078a18622..457fcc40c76 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/src/Generated/Models/_TypeDictionaryContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/src/Generated/Models/_TypeDictionaryContext.cs @@ -6,6 +6,7 @@ namespace _Type.Dictionary { + [ModelReaderWriterBuildable(typeof(InnerModel))] public partial class _TypeDictionaryContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/src/Generated/Models/_TypeModelEmptyContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/src/Generated/Models/_TypeModelEmptyContext.cs index 7e49f29aa4d..4f8a7686465 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/src/Generated/Models/_TypeModelEmptyContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/src/Generated/Models/_TypeModelEmptyContext.cs @@ -6,6 +6,9 @@ namespace _Type.Model.Empty { + [ModelReaderWriterBuildable(typeof(EmptyInput))] + [ModelReaderWriterBuildable(typeof(EmptyOutput))] + [ModelReaderWriterBuildable(typeof(EmptyInputOutput))] public partial class _TypeModelEmptyContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs index e298c7c2fe0..f56d5d5949f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Dog.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Model.Inheritance.EnumDiscriminator { + [PersistableModelProxy(typeof(UnknownDog))] public abstract partial class Dog : IJsonModel { internal Dog() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs index bac1a22763e..b94feb2a34e 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/Snake.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Model.Inheritance.EnumDiscriminator { + [PersistableModelProxy(typeof(UnknownSnake))] public abstract partial class Snake : IJsonModel { internal Snake() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/_TypeModelInheritanceEnumDiscriminatorContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/_TypeModelInheritanceEnumDiscriminatorContext.cs index 62306feb229..70183b996f9 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/_TypeModelInheritanceEnumDiscriminatorContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Generated/Models/_TypeModelInheritanceEnumDiscriminatorContext.cs @@ -6,6 +6,12 @@ namespace _Type.Model.Inheritance.EnumDiscriminator { + [ModelReaderWriterBuildable(typeof(Dog))] + [ModelReaderWriterBuildable(typeof(UnknownDog))] + [ModelReaderWriterBuildable(typeof(Golden))] + [ModelReaderWriterBuildable(typeof(Snake))] + [ModelReaderWriterBuildable(typeof(UnknownSnake))] + [ModelReaderWriterBuildable(typeof(Cobra))] public partial class _TypeModelInheritanceEnumDiscriminatorContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs index 2b994e540d0..815c2485173 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/Fish.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Model.Inheritance.NestedDiscriminator { + [PersistableModelProxy(typeof(UnknownFish))] public abstract partial class Fish : IJsonModel { internal Fish() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/_TypeModelInheritanceNestedDiscriminatorContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/_TypeModelInheritanceNestedDiscriminatorContext.cs index b1c52368505..dab6063817c 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/_TypeModelInheritanceNestedDiscriminatorContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Generated/Models/_TypeModelInheritanceNestedDiscriminatorContext.cs @@ -6,6 +6,13 @@ namespace _Type.Model.Inheritance.NestedDiscriminator { + [ModelReaderWriterBuildable(typeof(Fish))] + [ModelReaderWriterBuildable(typeof(UnknownFish))] + [ModelReaderWriterBuildable(typeof(Shark))] + [ModelReaderWriterBuildable(typeof(UnknownShark))] + [ModelReaderWriterBuildable(typeof(SawShark))] + [ModelReaderWriterBuildable(typeof(GoblinShark))] + [ModelReaderWriterBuildable(typeof(Salmon))] public partial class _TypeModelInheritanceNestedDiscriminatorContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/src/Generated/Models/_TypeModelInheritanceNotDiscriminatedContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/src/Generated/Models/_TypeModelInheritanceNotDiscriminatedContext.cs index 781ce1d9785..8455d012863 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/src/Generated/Models/_TypeModelInheritanceNotDiscriminatedContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/src/Generated/Models/_TypeModelInheritanceNotDiscriminatedContext.cs @@ -6,6 +6,9 @@ namespace _Type.Model.Inheritance.NotDiscriminated { + [ModelReaderWriterBuildable(typeof(Siamese))] + [ModelReaderWriterBuildable(typeof(Cat))] + [ModelReaderWriterBuildable(typeof(Pet))] public partial class _TypeModelInheritanceNotDiscriminatedContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/src/Generated/Models/_TypeModelInheritanceRecursiveContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/src/Generated/Models/_TypeModelInheritanceRecursiveContext.cs index 48e5d54327e..b4037978d29 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/src/Generated/Models/_TypeModelInheritanceRecursiveContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/src/Generated/Models/_TypeModelInheritanceRecursiveContext.cs @@ -6,6 +6,8 @@ namespace _Type.Model.Inheritance.Recursive { + [ModelReaderWriterBuildable(typeof(Extension))] + [ModelReaderWriterBuildable(typeof(Element))] public partial class _TypeModelInheritanceRecursiveContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs index ae72b55131f..46c4f020cb3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Bird.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Model.Inheritance.SingleDiscriminator { + [PersistableModelProxy(typeof(UnknownBird))] public abstract partial class Bird : IJsonModel { internal Bird() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs index 9cec6ff7173..8b16e7d19e6 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/Dinosaur.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Model.Inheritance.SingleDiscriminator { + [PersistableModelProxy(typeof(UnknownDinosaur))] public abstract partial class Dinosaur : IJsonModel { internal Dinosaur() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/_TypeModelInheritanceSingleDiscriminatorContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/_TypeModelInheritanceSingleDiscriminatorContext.cs index 2882d3c312e..78cec6dd88f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/_TypeModelInheritanceSingleDiscriminatorContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Generated/Models/_TypeModelInheritanceSingleDiscriminatorContext.cs @@ -6,6 +6,15 @@ namespace _Type.Model.Inheritance.SingleDiscriminator { + [ModelReaderWriterBuildable(typeof(Bird))] + [ModelReaderWriterBuildable(typeof(UnknownBird))] + [ModelReaderWriterBuildable(typeof(SeaGull))] + [ModelReaderWriterBuildable(typeof(Sparrow))] + [ModelReaderWriterBuildable(typeof(Goose))] + [ModelReaderWriterBuildable(typeof(Eagle))] + [ModelReaderWriterBuildable(typeof(Dinosaur))] + [ModelReaderWriterBuildable(typeof(UnknownDinosaur))] + [ModelReaderWriterBuildable(typeof(TRex))] public partial class _TypeModelInheritanceSingleDiscriminatorContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/src/Generated/Models/_TypeModelUsageContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/src/Generated/Models/_TypeModelUsageContext.cs index ad94d528135..9feac771bce 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/src/Generated/Models/_TypeModelUsageContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/src/Generated/Models/_TypeModelUsageContext.cs @@ -6,6 +6,9 @@ namespace _Type.Model.Usage { + [ModelReaderWriterBuildable(typeof(InputRecord))] + [ModelReaderWriterBuildable(typeof(OutputRecord))] + [ModelReaderWriterBuildable(typeof(InputOutputRecord))] public partial class _TypeModelUsageContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/src/Generated/Models/_TypeModelVisibilityContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/src/Generated/Models/_TypeModelVisibilityContext.cs index 0b2f24af5ab..3b0d205d0f4 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/src/Generated/Models/_TypeModelVisibilityContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/src/Generated/Models/_TypeModelVisibilityContext.cs @@ -6,6 +6,8 @@ namespace _Type.Model.Visibility { + [ModelReaderWriterBuildable(typeof(VisibilityModel))] + [ModelReaderWriterBuildable(typeof(ReadOnlyModel))] public partial class _TypeModelVisibilityContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs index 46390968f81..f7e9f72a561 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/ExtendsUnknownAdditionalPropertiesDiscriminated.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Property.AdditionalProperties { + [PersistableModelProxy(typeof(UnknownExtendsUnknownAdditionalPropertiesDiscriminated))] public abstract partial class ExtendsUnknownAdditionalPropertiesDiscriminated : IJsonModel { internal ExtendsUnknownAdditionalPropertiesDiscriminated() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs index 63f64af1537..3a7409587b3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/IsUnknownAdditionalPropertiesDiscriminated.Serialization.cs @@ -9,6 +9,7 @@ namespace _Type.Property.AdditionalProperties { + [PersistableModelProxy(typeof(UnknownIsUnknownAdditionalPropertiesDiscriminated))] public abstract partial class IsUnknownAdditionalPropertiesDiscriminated : IJsonModel { internal IsUnknownAdditionalPropertiesDiscriminated() => throw null; diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/_TypePropertyAdditionalPropertiesContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/_TypePropertyAdditionalPropertiesContext.cs index d413cd43dd3..548dd4e256f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/_TypePropertyAdditionalPropertiesContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Generated/Models/_TypePropertyAdditionalPropertiesContext.cs @@ -6,6 +6,45 @@ namespace _Type.Property.AdditionalProperties { + [ModelReaderWriterBuildable(typeof(ExtendsUnknownAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(ExtendsUnknownAdditionalPropertiesDerived))] + [ModelReaderWriterBuildable(typeof(ExtendsUnknownAdditionalPropertiesDiscriminated))] + [ModelReaderWriterBuildable(typeof(UnknownExtendsUnknownAdditionalPropertiesDiscriminated))] + [ModelReaderWriterBuildable(typeof(ExtendsUnknownAdditionalPropertiesDiscriminatedDerived))] + [ModelReaderWriterBuildable(typeof(IsUnknownAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(IsUnknownAdditionalPropertiesDerived))] + [ModelReaderWriterBuildable(typeof(IsUnknownAdditionalPropertiesDiscriminated))] + [ModelReaderWriterBuildable(typeof(UnknownIsUnknownAdditionalPropertiesDiscriminated))] + [ModelReaderWriterBuildable(typeof(IsUnknownAdditionalPropertiesDiscriminatedDerived))] + [ModelReaderWriterBuildable(typeof(ExtendsStringAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(IsStringAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(SpreadStringRecord))] + [ModelReaderWriterBuildable(typeof(ExtendsFloatAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(IsFloatAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(SpreadFloatRecord))] + [ModelReaderWriterBuildable(typeof(ExtendsModelAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(ModelForRecord))] + [ModelReaderWriterBuildable(typeof(IsModelAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(SpreadModelRecord))] + [ModelReaderWriterBuildable(typeof(ExtendsModelArrayAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(IsModelArrayAdditionalProperties))] + [ModelReaderWriterBuildable(typeof(SpreadModelArrayRecord))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadStringRecord))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadFloatRecord))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadModelRecord))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadModelArrayRecord))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadStringDerived))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadFloatDerived))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadModelDerived))] + [ModelReaderWriterBuildable(typeof(DifferentSpreadModelArrayDerived))] + [ModelReaderWriterBuildable(typeof(MultipleSpreadRecord))] + [ModelReaderWriterBuildable(typeof(SpreadRecordForUnion))] + [ModelReaderWriterBuildable(typeof(SpreadRecordForNonDiscriminatedUnion))] + [ModelReaderWriterBuildable(typeof(WidgetData0))] + [ModelReaderWriterBuildable(typeof(WidgetData1))] + [ModelReaderWriterBuildable(typeof(SpreadRecordForNonDiscriminatedUnion2))] + [ModelReaderWriterBuildable(typeof(WidgetData2))] + [ModelReaderWriterBuildable(typeof(SpreadRecordForNonDiscriminatedUnion3))] public partial class _TypePropertyAdditionalPropertiesContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/src/Generated/Models/_TypePropertyNullableContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/src/Generated/Models/_TypePropertyNullableContext.cs index 0ee24e1e978..9b3eeccc8fb 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/src/Generated/Models/_TypePropertyNullableContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/src/Generated/Models/_TypePropertyNullableContext.cs @@ -6,6 +6,14 @@ namespace _Type.Property.Nullable { + [ModelReaderWriterBuildable(typeof(StringProperty))] + [ModelReaderWriterBuildable(typeof(BytesProperty))] + [ModelReaderWriterBuildable(typeof(DatetimeProperty))] + [ModelReaderWriterBuildable(typeof(DurationProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsByteProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsModelProperty))] + [ModelReaderWriterBuildable(typeof(InnerModel))] + [ModelReaderWriterBuildable(typeof(CollectionsStringProperty))] public partial class _TypePropertyNullableContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/src/Generated/Models/_TypePropertyOptionalContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/src/Generated/Models/_TypePropertyOptionalContext.cs index 279aaa195b8..799454988a8 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/src/Generated/Models/_TypePropertyOptionalContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/src/Generated/Models/_TypePropertyOptionalContext.cs @@ -6,6 +6,22 @@ namespace _Type.Property.Optional { + [ModelReaderWriterBuildable(typeof(StringProperty))] + [ModelReaderWriterBuildable(typeof(BytesProperty))] + [ModelReaderWriterBuildable(typeof(DatetimeProperty))] + [ModelReaderWriterBuildable(typeof(DurationProperty))] + [ModelReaderWriterBuildable(typeof(PlainDateProperty))] + [ModelReaderWriterBuildable(typeof(PlainTimeProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsByteProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsModelProperty))] + [ModelReaderWriterBuildable(typeof(StringLiteralProperty))] + [ModelReaderWriterBuildable(typeof(IntLiteralProperty))] + [ModelReaderWriterBuildable(typeof(FloatLiteralProperty))] + [ModelReaderWriterBuildable(typeof(BooleanLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionStringLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionIntLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionFloatLiteralProperty))] + [ModelReaderWriterBuildable(typeof(RequiredAndOptionalProperty))] public partial class _TypePropertyOptionalContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/src/Generated/Models/_TypePropertyValueTypesContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/src/Generated/Models/_TypePropertyValueTypesContext.cs index 7c6e1db5919..fe554756e28 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/src/Generated/Models/_TypePropertyValueTypesContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/src/Generated/Models/_TypePropertyValueTypesContext.cs @@ -6,6 +6,36 @@ namespace _Type.Property.ValueTypes { + [ModelReaderWriterBuildable(typeof(BooleanProperty))] + [ModelReaderWriterBuildable(typeof(StringProperty))] + [ModelReaderWriterBuildable(typeof(BytesProperty))] + [ModelReaderWriterBuildable(typeof(IntProperty))] + [ModelReaderWriterBuildable(typeof(FloatProperty))] + [ModelReaderWriterBuildable(typeof(DecimalProperty))] + [ModelReaderWriterBuildable(typeof(Decimal128Property))] + [ModelReaderWriterBuildable(typeof(DatetimeProperty))] + [ModelReaderWriterBuildable(typeof(DurationProperty))] + [ModelReaderWriterBuildable(typeof(EnumProperty))] + [ModelReaderWriterBuildable(typeof(ExtensibleEnumProperty))] + [ModelReaderWriterBuildable(typeof(ModelProperty))] + [ModelReaderWriterBuildable(typeof(InnerModel))] + [ModelReaderWriterBuildable(typeof(CollectionsStringProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsIntProperty))] + [ModelReaderWriterBuildable(typeof(CollectionsModelProperty))] + [ModelReaderWriterBuildable(typeof(DictionaryStringProperty))] + [ModelReaderWriterBuildable(typeof(NeverProperty))] + [ModelReaderWriterBuildable(typeof(UnknownStringProperty))] + [ModelReaderWriterBuildable(typeof(UnknownIntProperty))] + [ModelReaderWriterBuildable(typeof(UnknownDictProperty))] + [ModelReaderWriterBuildable(typeof(UnknownArrayProperty))] + [ModelReaderWriterBuildable(typeof(StringLiteralProperty))] + [ModelReaderWriterBuildable(typeof(IntLiteralProperty))] + [ModelReaderWriterBuildable(typeof(FloatLiteralProperty))] + [ModelReaderWriterBuildable(typeof(BooleanLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionStringLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionIntLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionFloatLiteralProperty))] + [ModelReaderWriterBuildable(typeof(UnionEnumValueProperty))] public partial class _TypePropertyValueTypesContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/src/Generated/Models/_TypeUnionContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/src/Generated/Models/_TypeUnionContext.cs index 452172e5c44..a2927b4b5e3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/src/Generated/Models/_TypeUnionContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/src/Generated/Models/_TypeUnionContext.cs @@ -6,6 +6,22 @@ namespace _Type.Union { + [ModelReaderWriterBuildable(typeof(GetResponse))] + [ModelReaderWriterBuildable(typeof(GetResponse1))] + [ModelReaderWriterBuildable(typeof(GetResponse2))] + [ModelReaderWriterBuildable(typeof(GetResponse3))] + [ModelReaderWriterBuildable(typeof(GetResponse4))] + [ModelReaderWriterBuildable(typeof(GetResponse5))] + [ModelReaderWriterBuildable(typeof(Cat))] + [ModelReaderWriterBuildable(typeof(Dog))] + [ModelReaderWriterBuildable(typeof(GetResponse6))] + [ModelReaderWriterBuildable(typeof(EnumsOnlyCases))] + [ModelReaderWriterBuildable(typeof(GetResponse7))] + [ModelReaderWriterBuildable(typeof(StringAndArrayCases))] + [ModelReaderWriterBuildable(typeof(GetResponse8))] + [ModelReaderWriterBuildable(typeof(MixedLiteralsCases))] + [ModelReaderWriterBuildable(typeof(GetResponse9))] + [ModelReaderWriterBuildable(typeof(MixedTypesCases))] public partial class _TypeUnionContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/src/Generated/Models/VersioningAddedV1Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/src/Generated/Models/VersioningAddedV1Context.cs index 4a1b81b5bd3..3d27ee7498d 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/src/Generated/Models/VersioningAddedV1Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/src/Generated/Models/VersioningAddedV1Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.Added; namespace Versioning.Added.V1 { + [ModelReaderWriterBuildable(typeof(ModelV1))] public partial class VersioningAddedV1Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/src/Generated/Models/VersioningAddedV2Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/src/Generated/Models/VersioningAddedV2Context.cs index a79be6548c2..07f6e8b216f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/src/Generated/Models/VersioningAddedV2Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/src/Generated/Models/VersioningAddedV2Context.cs @@ -3,9 +3,12 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.Added; namespace Versioning.Added.V2 { + [ModelReaderWriterBuildable(typeof(ModelV1))] + [ModelReaderWriterBuildable(typeof(ModelV2))] public partial class VersioningAddedV2Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/src/Generated/Models/VersioningMadeOptionalV1Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/src/Generated/Models/VersioningMadeOptionalV1Context.cs index d4555e7f213..7c7a9e4744b 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/src/Generated/Models/VersioningMadeOptionalV1Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/src/Generated/Models/VersioningMadeOptionalV1Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.MadeOptional; namespace Versioning.MadeOptional.V1 { + [ModelReaderWriterBuildable(typeof(TestModel))] public partial class VersioningMadeOptionalV1Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/src/Generated/Models/VersioningMadeOptionalV2Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/src/Generated/Models/VersioningMadeOptionalV2Context.cs index ed8ef46d942..18b7e4fd8ca 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/src/Generated/Models/VersioningMadeOptionalV2Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/src/Generated/Models/VersioningMadeOptionalV2Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.MadeOptional; namespace Versioning.MadeOptional.V2 { + [ModelReaderWriterBuildable(typeof(TestModel))] public partial class VersioningMadeOptionalV2Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/src/Generated/Models/VersioningRemovedV1Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/src/Generated/Models/VersioningRemovedV1Context.cs index 90772a416d5..df15da84a05 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/src/Generated/Models/VersioningRemovedV1Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/src/Generated/Models/VersioningRemovedV1Context.cs @@ -3,9 +3,13 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.Removed; namespace Versioning.Removed.V1 { + [ModelReaderWriterBuildable(typeof(ModelV1))] + [ModelReaderWriterBuildable(typeof(ModelV2))] + [ModelReaderWriterBuildable(typeof(ModelV3))] public partial class VersioningRemovedV1Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/src/Generated/Models/VersioningRemovedV2Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/src/Generated/Models/VersioningRemovedV2Context.cs index 734e678fd54..493f68110f7 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/src/Generated/Models/VersioningRemovedV2Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/src/Generated/Models/VersioningRemovedV2Context.cs @@ -3,9 +3,12 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.Removed; namespace Versioning.Removed.V2 { + [ModelReaderWriterBuildable(typeof(ModelV2))] + [ModelReaderWriterBuildable(typeof(ModelV3))] public partial class VersioningRemovedV2Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/src/Generated/Models/VersioningRemovedV2PreviewContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/src/Generated/Models/VersioningRemovedV2PreviewContext.cs index b8f933b2e93..45d1c54726a 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/src/Generated/Models/VersioningRemovedV2PreviewContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/src/Generated/Models/VersioningRemovedV2PreviewContext.cs @@ -3,9 +3,13 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.Removed; namespace Versioning.Removed.V2Preview { + [ModelReaderWriterBuildable(typeof(ModelV1))] + [ModelReaderWriterBuildable(typeof(ModelV2))] + [ModelReaderWriterBuildable(typeof(ModelV3))] public partial class VersioningRemovedV2PreviewContext : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/src/Generated/Models/VersioningRenamedFromV1Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/src/Generated/Models/VersioningRenamedFromV1Context.cs index ccd1eab5a5d..f4d70bd68ae 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/src/Generated/Models/VersioningRenamedFromV1Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/src/Generated/Models/VersioningRenamedFromV1Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.RenamedFrom; namespace Versioning.RenamedFrom.V1 { + [ModelReaderWriterBuildable(typeof(OldModel))] public partial class VersioningRenamedFromV1Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/src/Generated/Models/VersioningRenamedFromV2Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/src/Generated/Models/VersioningRenamedFromV2Context.cs index a6bf39e858b..89ad6f39624 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/src/Generated/Models/VersioningRenamedFromV2Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/src/Generated/Models/VersioningRenamedFromV2Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.RenamedFrom; namespace Versioning.RenamedFrom.V2 { + [ModelReaderWriterBuildable(typeof(NewModel))] public partial class VersioningRenamedFromV2Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/src/Generated/Models/VersioningTypeChangedFromV1Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/src/Generated/Models/VersioningTypeChangedFromV1Context.cs index d476fba3977..e93835d3a7d 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/src/Generated/Models/VersioningTypeChangedFromV1Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/src/Generated/Models/VersioningTypeChangedFromV1Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.TypeChangedFrom; namespace Versioning.TypeChangedFrom.V1 { + [ModelReaderWriterBuildable(typeof(TestModel))] public partial class VersioningTypeChangedFromV1Context : ModelReaderWriterContext { } diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/src/Generated/Models/VersioningTypeChangedFromV2Context.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/src/Generated/Models/VersioningTypeChangedFromV2Context.cs index 0c560e183a6..a5e364edd47 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/src/Generated/Models/VersioningTypeChangedFromV2Context.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/src/Generated/Models/VersioningTypeChangedFromV2Context.cs @@ -3,9 +3,11 @@ #nullable disable using System.ClientModel.Primitives; +using Versioning.TypeChangedFrom; namespace Versioning.TypeChangedFrom.V2 { + [ModelReaderWriterBuildable(typeof(TestModel))] public partial class VersioningTypeChangedFromV2Context : ModelReaderWriterContext { } From 0ef418ff5d523d7267cada443b6b8c7afbbaef1c Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Fri, 18 Jul 2025 15:47:56 -0700 Subject: [PATCH 19/21] update perf for algorithm --- .../src/Properties/AssemblyInfo.cs | 3 +- .../ModelReaderWriterContextDefinition.cs | 71 ++++------ .../test/Properties/AssemblyInfo.cs | 6 + ...ModelReaderWriterContextDefinitionTests.cs | 133 +++++++++++------- .../test/TestHelpers/MockHelpers.cs | 17 ++- ...osoft.TypeSpec.Generator.Tests.Perf.csproj | 2 + ...lReaderWriterContextDefinitionBenchmark.cs | 119 ++++++++++++++++ 7 files changed, 254 insertions(+), 97 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs index 616e6935891..577f6639db2 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs @@ -1,6 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.ClientModel.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] +[assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.Tests.Perf, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index a4024ab7995..9791f8f8e57 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -54,12 +54,12 @@ private HashSet CollectBuildableTypes() // Get all model providers from the output library var modelProviders = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders .OfType() - .ToList(); + .ToDictionary(mp => mp.Type, mp => mp, new CSharpTypeNameComparer()); // Process each model recursively - foreach (var modelProvider in modelProviders) + foreach (var modelProvider in modelProviders.Values) { - CollectBuildableTypesRecursive(modelProvider.Type, buildableTypes, visitedTypes); + CollectBuildableTypesRecursive(modelProvider.Type, buildableTypes, visitedTypes, modelProviders); } return buildableTypes; @@ -68,71 +68,57 @@ private HashSet CollectBuildableTypes() /// /// Recursively collects all types that implement IPersistableModel. /// - private void CollectBuildableTypesRecursive(CSharpType type, HashSet buildableTypes, HashSet visitedTypes) + private void CollectBuildableTypesRecursive(CSharpType currentType, HashSet buildableTypes, HashSet visitedTypes, Dictionary modelProviders) { // Avoid infinite recursion by checking if we've already visited this type - if (visitedTypes.Contains(type) || type.IsFrameworkType) + if (visitedTypes.Contains(currentType)) { return; } - visitedTypes.Add(type); + visitedTypes.Add(currentType); // Check if this type implements IPersistableModel - if (ImplementsIPersistableModel(type)) + if (ImplementsIPersistableModel(currentType, modelProviders, out ModelProvider? model)) { - buildableTypes.Add(type); + buildableTypes.Add(currentType); - // Look for all properties of this type that are also IPersistableModel - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - if (modelProvider != null) + if (model is not null) { // Check all properties of this model - foreach (var property in modelProvider.Properties) + foreach (var property in model.Properties) { - if (property.Type.IsCollection) - { - // For collections, check the element type - CollectBuildableTypesRecursive(property.Type.ElementType, buildableTypes, visitedTypes); - } - else - { - // For regular properties, check the property type - CollectBuildableTypesRecursive(property.Type, buildableTypes, visitedTypes); - } + var propertyType = property.Type.IsCollection ? GetInnerMostElement(property.Type) : property.Type; + CollectBuildableTypesRecursive(propertyType, buildableTypes, visitedTypes, modelProviders); } } } } + private CSharpType GetInnerMostElement(CSharpType type) + { + var result = type.ElementType; + while (result.IsCollection) + { + result = result.ElementType; + } + return result; + } + /// /// Checks if a type implements IPersistableModel interface. /// - private bool ImplementsIPersistableModel(CSharpType type) + private bool ImplementsIPersistableModel(CSharpType type, Dictionary modelProviders, out ModelProvider? model) { - // Check if the type is a framework type (System.* types) - if (type.IsFrameworkType) + if (modelProviders.TryGetValue(type, out model)) { - return false; + return model.SerializationProviders.OfType().Any(); } - // Check if the type has a model provider in the current library (local models) - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - if (modelProvider != null) - { - return true; - } + if (!type.IsFrameworkType || type.IsEnum || type.IsLiteral) + return false; - // For dependency models (models from other libraries), assume they implement IPersistableModel - // if they are not framework types, not literals, not enums, and not generic types - // This handles models that are referenced from dependency libraries - return !type.IsFrameworkType && !type.IsLiteral && !type.IsEnum && !type.IsGenericType; + return type.FrameworkType.GetInterfaces().Any(i => i.Name == "IPersistableModel`1" || i.Name == "IJsonModel`1"); } protected override XmlDocProvider BuildXmlDocs() @@ -182,6 +168,7 @@ public int GetHashCode(CSharpType obj) { HashCode hashCode = new HashCode(); hashCode.Add(obj.Namespace); + hashCode.Add(obj.Name); return hashCode.ToHashCode(); } } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..403c4390844 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.Tests.Perf, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs index 4a31135d487..2a66c20dcf1 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs @@ -5,11 +5,10 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using Microsoft.TypeSpec.Generator.ClientModel.Providers; -using Microsoft.TypeSpec.Generator.ClientModel.Tests; using Microsoft.TypeSpec.Generator.Input; using Microsoft.TypeSpec.Generator.Primitives; -using Microsoft.TypeSpec.Generator.Providers; using Microsoft.TypeSpec.Generator.Tests.Common; using NUnit.Framework; @@ -23,7 +22,7 @@ public void ValidateModelReaderWriterContextIsGenerated() MockHelpers.LoadMockGenerator(); var contextDefinition = new ModelReaderWriterContextDefinition(); - + Assert.IsNotNull(contextDefinition); Assert.IsNotNull(contextDefinition.Name); Assert.IsTrue(contextDefinition.Name.EndsWith("Context")); @@ -41,19 +40,19 @@ public void ValidateModelReaderWriterBuildableAttributesAreGenerated() var mockGenerator = MockHelpers.LoadMockGenerator( inputModels: () => new List { - InputFactory.Model("TestModel", properties: new[] - { + InputFactory.Model("TestModel", properties: + [ InputFactory.Property("StringProperty", InputPrimitiveType.String), InputFactory.Property("IntProperty", InputPrimitiveType.Int32) - }) + ]) }); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly one ModelReaderWriterBuildableAttribute exists since TestModel has only primitive properties var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(1, buildableAttributes.Count(), "Exactly one ModelReaderWriterBuildableAttribute should be generated for TestModel"); @@ -63,26 +62,26 @@ public void ValidateModelReaderWriterBuildableAttributesAreGenerated() public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() { // Create a model with a property that references another model - var nestedModel = InputFactory.Model("NestedModel", properties: new[] - { + var nestedModel = InputFactory.Model("NestedModel", properties: + [ InputFactory.Property("NestedValue", InputPrimitiveType.String) - }); + ]); - var parentModel = InputFactory.Model("ParentModel", properties: new[] - { + var parentModel = InputFactory.Model("ParentModel", properties: + [ InputFactory.Property("NestedProperty", nestedModel), InputFactory.Property("SimpleProperty", InputPrimitiveType.String) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { parentModel, nestedModel }); + inputModels: () => [parentModel, nestedModel]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for nested models"); @@ -92,25 +91,25 @@ public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperties() { // Create a model with a collection property containing another model - var itemModel = InputFactory.Model("ItemModel", properties: new[] - { + var itemModel = InputFactory.Model("ItemModel", properties: + [ InputFactory.Property("ItemValue", InputPrimitiveType.String) - }); + ]); - var collectionModel = InputFactory.Model("CollectionModel", properties: new[] - { + var collectionModel = InputFactory.Model("CollectionModel", properties: + [ InputFactory.Property("Items", InputFactory.Array(itemModel)) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { collectionModel, itemModel }); + inputModels: () => [collectionModel, itemModel]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for collection item models"); @@ -120,37 +119,37 @@ public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperti public void ValidateModelReaderWriterBuildableAttributesAvoidDuplicates() { // Create models with circular references to test duplicate handling - var modelA = InputFactory.Model("ModelA", properties: new[] - { + var modelA = InputFactory.Model("ModelA", properties: + [ InputFactory.Property("PropertyA", InputPrimitiveType.String) - }); + ]); - var modelB = InputFactory.Model("ModelB", properties: new[] - { + var modelB = InputFactory.Model("ModelB", properties: + [ InputFactory.Property("PropertyB", InputPrimitiveType.String), InputFactory.Property("ModelARef", modelA) - }); + ]); // Add a property to ModelA that references ModelB to create a circular reference - var modelAWithCircularRef = InputFactory.Model("ModelA", properties: new[] - { + var modelAWithCircularRef = InputFactory.Model("ModelA", properties: + [ InputFactory.Property("PropertyA", InputPrimitiveType.String), InputFactory.Property("ModelBRef", modelB) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { modelAWithCircularRef, modelB }); + inputModels: () => [modelAWithCircularRef, modelB]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); - + // Check that no duplicate attributes exist var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); var uniqueTypes = buildableAttributes.Select(a => a.Arguments.First().ToString()).Distinct().ToList(); - - Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, + + Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, "No duplicate ModelReaderWriterBuildableAttributes should be generated"); } @@ -159,32 +158,62 @@ public void ValidateModelReaderWriterBuildableAttributesIncludeDependencyModels( { // Create a model with a property that references a model from a dependency library // The dependency model won't have a model provider in the current library - var dependencyModel = InputFactory.Model("DependencyModel", properties: new[] - { - InputFactory.Property("DependencyValue", InputPrimitiveType.String) - }); - - var parentModel = InputFactory.Model("ParentModel", properties: new[] - { + var dependencyModel = InputFactory.Model("DependencyModel"); + + var parentModel = InputFactory.Model("ParentModel", properties: + [ InputFactory.Property("DependencyProperty", dependencyModel), InputFactory.Property("SimpleProperty", InputPrimitiveType.String) - }); + ]); // Only include the parentModel in the mock generator, simulating that // dependencyModel is from a dependency library var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { parentModel }); + inputModels: () => [parentModel], + createCSharpTypeCore: input => + { + return new CSharpType(typeof(DependencyModel)); + }, + createCSharpTypeCoreFallback: input => input.Name == "DependencyModel"); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist: // one for ParentModel and one for the dependency model var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for models with dependency references"); } + + private class DependencyModel : IJsonModel + { + DependencyModel? IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + DependencyModel? IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + } } -} \ No newline at end of file +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs index 687ec6ab9eb..f68f688d513 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs @@ -68,7 +68,8 @@ public static Mock LoadMockGenerator( HttpMessageApi? httpMessageApi = null, RequestContentApi? requestContentApi = null, Func? auth = null, - bool includeXmlDocs = false) + bool includeXmlDocs = false, + Func? createCSharpTypeCoreFallback = null) { IReadOnlyList inputNsApiVersions = apiVersions?.Invoke() ?? []; IReadOnlyList inputNsLiterals = inputLiterals?.Invoke() ?? []; @@ -110,7 +111,19 @@ public static Mock LoadMockGenerator( if (createCSharpTypeCore is not null) { - mockTypeFactory.Protected().Setup("CreateCSharpTypeCore", ItExpr.IsAny()).Returns(createCSharpTypeCore); + if (createCSharpTypeCoreFallback is not null) + { + mockTypeFactory.Protected() + .Setup("CreateCSharpTypeCore", ItExpr.IsAny()) + .Returns((InputType input) => + createCSharpTypeCoreFallback(input) + ? createCSharpTypeCore(input) + : null!); + } + else + { + mockTypeFactory.Protected().Setup("CreateCSharpTypeCore", ItExpr.IsAny()).Returns(createCSharpTypeCore); + } } if (createClientCore is not null) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj index 44f0f8602d8..2923ecb6971 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj @@ -2,7 +2,9 @@ + + diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs new file mode 100644 index 00000000000..45fa669af3d --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using BenchmarkDotNet.Attributes; +using Microsoft.TypeSpec.Generator.ClientModel.Providers; +using Microsoft.TypeSpec.Generator.ClientModel.Tests; +using Microsoft.TypeSpec.Generator.Input; +using Microsoft.TypeSpec.Generator.Statements; +using Microsoft.TypeSpec.Generator.Tests.Common; + +namespace Microsoft.TypeSpec.Generator.ClientModel.Perf +{ + [MemoryDiagnoser] + public class ModelReaderWriterContextDefinitionBenchmark + { + private ModelReaderWriterContextDefinition? _contextDefinition; + private Func>? _privateDelegate; + + [Params(1, 10, 100)] + public int ModelCount; + + [Params(1, 10, 100)] + public int SimplePropertyCount; + + [Params(0, 1, 2, 5)] + public int NestingLevel; + + [GlobalSetup] + public void Setup() + { + var generator = MockHelpers.LoadMockGenerator(inputModels: () => GetMockModels(ModelCount, SimplePropertyCount, NestingLevel)); + + _contextDefinition = generator.Object.OutputLibrary.TypeProviders.OfType().FirstOrDefault(); + + var methodInfo = typeof(ModelReaderWriterContextDefinition).GetMethod("BuildAttributes", BindingFlags.Instance | BindingFlags.NonPublic); + _privateDelegate = CreateDelegate>>(methodInfo!); + } + + [GlobalCleanup] + public void Cleanup() + { + _contextDefinition = null; + } + + [Benchmark] + public IReadOnlyList CollectBuildableTypes() + { + return _privateDelegate!(_contextDefinition!); + } + + private IReadOnlyList GetMockModels(int modelCount, int simplePropertyCount, int nestingLevel) + { + return + [ + .. GetSimpleModels(modelCount, simplePropertyCount, nestingLevel), + ]; + } + + private static IEnumerable GetSimpleModels(int modelCount, int simplePropertyCount, int nestingLevel) + { + for (int i = 0; i < modelCount; i++) + { + yield return GetNestedModel(i, simplePropertyCount, nestingLevel); + } + } + + private static IEnumerable GetSimpleProperties(int simplePropertyCount) + { + for (int i = 0; i < simplePropertyCount; i++) + { + yield return InputFactory.Property($"Property{i}", InputPrimitiveType.String, isRequired: true); + } + } + + private static InputModelType GetNestedModel(int modelNumber, int simplePropertyCount, int nestingLevel) + { + var nestedModel = GetRecursiveNestedModel(modelNumber, simplePropertyCount, nestingLevel); + return InputFactory.Model( + $"Model{modelNumber}", + properties: nestedModel is null + ? [.. GetSimpleProperties(simplePropertyCount)] + : [.. GetSimpleProperties(simplePropertyCount), InputFactory.Property($"Property{simplePropertyCount}", nestedModel)]); + } + + private static InputModelType? GetRecursiveNestedModel(int modelNumber, int simplePropertyCount, int nestingLevel) + { + if (nestingLevel <= 0) + return null; + + var nestedModel = GetRecursiveNestedModel(modelNumber, simplePropertyCount, nestingLevel - 1); + return InputFactory.Model( + $"NestedModel{modelNumber}_{nestingLevel}", + properties: nestedModel is null + ? [.. GetSimpleProperties(simplePropertyCount)] + : [.. GetSimpleProperties(simplePropertyCount), InputFactory.Property($"Property{simplePropertyCount}", nestedModel)]); + } + + private static T CreateDelegate(MethodInfo methodInfo) + { + var instanceParam = Expression.Parameter(typeof(object), "target"); + var parameters = methodInfo.GetParameters() + .Select(p => Expression.Parameter(p.ParameterType, p.Name)) + .ToArray(); + + var instanceCast = Expression.Convert(instanceParam, methodInfo.DeclaringType!); + var methodCall = Expression.Call(instanceCast, methodInfo, parameters); + + var lambdaParams = new ParameterExpression[] { instanceParam }.Concat(parameters); + var lambda = Expression.Lambda(methodCall, lambdaParams); + + return lambda.Compile(); + } + } +} From b5878b63a794f18d77a277830cba5542ede94088 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Fri, 18 Jul 2025 15:50:39 -0700 Subject: [PATCH 20/21] update perf for algorithm (#7962) --- .../src/Properties/AssemblyInfo.cs | 3 +- .../ModelReaderWriterContextDefinition.cs | 71 ++++------ .../test/Properties/AssemblyInfo.cs | 6 + ...ModelReaderWriterContextDefinitionTests.cs | 133 +++++++++++------- .../test/TestHelpers/MockHelpers.cs | 17 ++- ...osoft.TypeSpec.Generator.Tests.Perf.csproj | 2 + ...lReaderWriterContextDefinitionBenchmark.cs | 119 ++++++++++++++++ 7 files changed, 254 insertions(+), 97 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs index 616e6935891..577f6639db2 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Properties/AssemblyInfo.cs @@ -1,6 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.ClientModel.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] +[assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.Tests.Perf, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs index a4024ab7995..9791f8f8e57 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs @@ -54,12 +54,12 @@ private HashSet CollectBuildableTypes() // Get all model providers from the output library var modelProviders = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders .OfType() - .ToList(); + .ToDictionary(mp => mp.Type, mp => mp, new CSharpTypeNameComparer()); // Process each model recursively - foreach (var modelProvider in modelProviders) + foreach (var modelProvider in modelProviders.Values) { - CollectBuildableTypesRecursive(modelProvider.Type, buildableTypes, visitedTypes); + CollectBuildableTypesRecursive(modelProvider.Type, buildableTypes, visitedTypes, modelProviders); } return buildableTypes; @@ -68,71 +68,57 @@ private HashSet CollectBuildableTypes() /// /// Recursively collects all types that implement IPersistableModel. /// - private void CollectBuildableTypesRecursive(CSharpType type, HashSet buildableTypes, HashSet visitedTypes) + private void CollectBuildableTypesRecursive(CSharpType currentType, HashSet buildableTypes, HashSet visitedTypes, Dictionary modelProviders) { // Avoid infinite recursion by checking if we've already visited this type - if (visitedTypes.Contains(type) || type.IsFrameworkType) + if (visitedTypes.Contains(currentType)) { return; } - visitedTypes.Add(type); + visitedTypes.Add(currentType); // Check if this type implements IPersistableModel - if (ImplementsIPersistableModel(type)) + if (ImplementsIPersistableModel(currentType, modelProviders, out ModelProvider? model)) { - buildableTypes.Add(type); + buildableTypes.Add(currentType); - // Look for all properties of this type that are also IPersistableModel - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - if (modelProvider != null) + if (model is not null) { // Check all properties of this model - foreach (var property in modelProvider.Properties) + foreach (var property in model.Properties) { - if (property.Type.IsCollection) - { - // For collections, check the element type - CollectBuildableTypesRecursive(property.Type.ElementType, buildableTypes, visitedTypes); - } - else - { - // For regular properties, check the property type - CollectBuildableTypesRecursive(property.Type, buildableTypes, visitedTypes); - } + var propertyType = property.Type.IsCollection ? GetInnerMostElement(property.Type) : property.Type; + CollectBuildableTypesRecursive(propertyType, buildableTypes, visitedTypes, modelProviders); } } } } + private CSharpType GetInnerMostElement(CSharpType type) + { + var result = type.ElementType; + while (result.IsCollection) + { + result = result.ElementType; + } + return result; + } + /// /// Checks if a type implements IPersistableModel interface. /// - private bool ImplementsIPersistableModel(CSharpType type) + private bool ImplementsIPersistableModel(CSharpType type, Dictionary modelProviders, out ModelProvider? model) { - // Check if the type is a framework type (System.* types) - if (type.IsFrameworkType) + if (modelProviders.TryGetValue(type, out model)) { - return false; + return model.SerializationProviders.OfType().Any(); } - // Check if the type has a model provider in the current library (local models) - var modelProvider = ScmCodeModelGenerator.Instance.OutputLibrary.TypeProviders - .OfType() - .FirstOrDefault(m => m.Type.Equals(type)); - - if (modelProvider != null) - { - return true; - } + if (!type.IsFrameworkType || type.IsEnum || type.IsLiteral) + return false; - // For dependency models (models from other libraries), assume they implement IPersistableModel - // if they are not framework types, not literals, not enums, and not generic types - // This handles models that are referenced from dependency libraries - return !type.IsFrameworkType && !type.IsLiteral && !type.IsEnum && !type.IsGenericType; + return type.FrameworkType.GetInterfaces().Any(i => i.Name == "IPersistableModel`1" || i.Name == "IJsonModel`1"); } protected override XmlDocProvider BuildXmlDocs() @@ -182,6 +168,7 @@ public int GetHashCode(CSharpType obj) { HashCode hashCode = new HashCode(); hashCode.Add(obj.Namespace); + hashCode.Add(obj.Name); return hashCode.ToHashCode(); } } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..403c4390844 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.TypeSpec.Generator.Tests.Perf, PublicKey=002400000480000094000000060200000024000052534131000400000100010041df4fe80c5af6ff9a410db5a173b0ce24ad68764c623e308b1584a88b1d1d82277f746c1cccba48997e13db3366d5ed676576ffd293293baf42c643f008ba2e8a556e25e529c0407a38506555340749559f5100e6fd78cc935bb6c82d2af303beb0d3c6563400659610759b4ed5cb2e0faf36b17e6842f04cdc544c74e051ba")] diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs index 4a31135d487..2a66c20dcf1 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/ModelReaderWriterContextDefinitionTests.cs @@ -5,11 +5,10 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using Microsoft.TypeSpec.Generator.ClientModel.Providers; -using Microsoft.TypeSpec.Generator.ClientModel.Tests; using Microsoft.TypeSpec.Generator.Input; using Microsoft.TypeSpec.Generator.Primitives; -using Microsoft.TypeSpec.Generator.Providers; using Microsoft.TypeSpec.Generator.Tests.Common; using NUnit.Framework; @@ -23,7 +22,7 @@ public void ValidateModelReaderWriterContextIsGenerated() MockHelpers.LoadMockGenerator(); var contextDefinition = new ModelReaderWriterContextDefinition(); - + Assert.IsNotNull(contextDefinition); Assert.IsNotNull(contextDefinition.Name); Assert.IsTrue(contextDefinition.Name.EndsWith("Context")); @@ -41,19 +40,19 @@ public void ValidateModelReaderWriterBuildableAttributesAreGenerated() var mockGenerator = MockHelpers.LoadMockGenerator( inputModels: () => new List { - InputFactory.Model("TestModel", properties: new[] - { + InputFactory.Model("TestModel", properties: + [ InputFactory.Property("StringProperty", InputPrimitiveType.String), InputFactory.Property("IntProperty", InputPrimitiveType.Int32) - }) + ]) }); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly one ModelReaderWriterBuildableAttribute exists since TestModel has only primitive properties var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(1, buildableAttributes.Count(), "Exactly one ModelReaderWriterBuildableAttribute should be generated for TestModel"); @@ -63,26 +62,26 @@ public void ValidateModelReaderWriterBuildableAttributesAreGenerated() public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() { // Create a model with a property that references another model - var nestedModel = InputFactory.Model("NestedModel", properties: new[] - { + var nestedModel = InputFactory.Model("NestedModel", properties: + [ InputFactory.Property("NestedValue", InputPrimitiveType.String) - }); + ]); - var parentModel = InputFactory.Model("ParentModel", properties: new[] - { + var parentModel = InputFactory.Model("ParentModel", properties: + [ InputFactory.Property("NestedProperty", nestedModel), InputFactory.Property("SimpleProperty", InputPrimitiveType.String) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { parentModel, nestedModel }); + inputModels: () => [parentModel, nestedModel]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for nested models"); @@ -92,25 +91,25 @@ public void ValidateModelReaderWriterBuildableAttributesIncludeNestedModels() public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperties() { // Create a model with a collection property containing another model - var itemModel = InputFactory.Model("ItemModel", properties: new[] - { + var itemModel = InputFactory.Model("ItemModel", properties: + [ InputFactory.Property("ItemValue", InputPrimitiveType.String) - }); + ]); - var collectionModel = InputFactory.Model("CollectionModel", properties: new[] - { + var collectionModel = InputFactory.Model("CollectionModel", properties: + [ InputFactory.Property("Items", InputFactory.Array(itemModel)) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { collectionModel, itemModel }); + inputModels: () => [collectionModel, itemModel]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist for both models var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for collection item models"); @@ -120,37 +119,37 @@ public void ValidateModelReaderWriterBuildableAttributesHandleCollectionProperti public void ValidateModelReaderWriterBuildableAttributesAvoidDuplicates() { // Create models with circular references to test duplicate handling - var modelA = InputFactory.Model("ModelA", properties: new[] - { + var modelA = InputFactory.Model("ModelA", properties: + [ InputFactory.Property("PropertyA", InputPrimitiveType.String) - }); + ]); - var modelB = InputFactory.Model("ModelB", properties: new[] - { + var modelB = InputFactory.Model("ModelB", properties: + [ InputFactory.Property("PropertyB", InputPrimitiveType.String), InputFactory.Property("ModelARef", modelA) - }); + ]); // Add a property to ModelA that references ModelB to create a circular reference - var modelAWithCircularRef = InputFactory.Model("ModelA", properties: new[] - { + var modelAWithCircularRef = InputFactory.Model("ModelA", properties: + [ InputFactory.Property("PropertyA", InputPrimitiveType.String), InputFactory.Property("ModelBRef", modelB) - }); + ]); var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { modelAWithCircularRef, modelB }); + inputModels: () => [modelAWithCircularRef, modelB]); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); - + // Check that no duplicate attributes exist var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); var uniqueTypes = buildableAttributes.Select(a => a.Arguments.First().ToString()).Distinct().ToList(); - - Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, + + Assert.AreEqual(buildableAttributes.Count(), uniqueTypes.Count, "No duplicate ModelReaderWriterBuildableAttributes should be generated"); } @@ -159,32 +158,62 @@ public void ValidateModelReaderWriterBuildableAttributesIncludeDependencyModels( { // Create a model with a property that references a model from a dependency library // The dependency model won't have a model provider in the current library - var dependencyModel = InputFactory.Model("DependencyModel", properties: new[] - { - InputFactory.Property("DependencyValue", InputPrimitiveType.String) - }); - - var parentModel = InputFactory.Model("ParentModel", properties: new[] - { + var dependencyModel = InputFactory.Model("DependencyModel"); + + var parentModel = InputFactory.Model("ParentModel", properties: + [ InputFactory.Property("DependencyProperty", dependencyModel), InputFactory.Property("SimpleProperty", InputPrimitiveType.String) - }); + ]); // Only include the parentModel in the mock generator, simulating that // dependencyModel is from a dependency library var mockGenerator = MockHelpers.LoadMockGenerator( - inputModels: () => new List { parentModel }); + inputModels: () => [parentModel], + createCSharpTypeCore: input => + { + return new CSharpType(typeof(DependencyModel)); + }, + createCSharpTypeCoreFallback: input => input.Name == "DependencyModel"); var contextDefinition = new ModelReaderWriterContextDefinition(); var attributes = contextDefinition.Attributes; - + Assert.IsNotNull(attributes); Assert.IsTrue(attributes.Count > 0); - + // Check that exactly two ModelReaderWriterBuildableAttribute exist: // one for ParentModel and one for the dependency model var buildableAttributes = attributes.Where(a => a.Type.IsFrameworkType && a.Type.FrameworkType == typeof(ModelReaderWriterBuildableAttribute)); Assert.AreEqual(2, buildableAttributes.Count(), "Exactly two ModelReaderWriterBuildableAttributes should be generated for models with dependency references"); } + + private class DependencyModel : IJsonModel + { + DependencyModel? IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + DependencyModel? IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + throw new NotImplementedException(); + } + } } -} \ No newline at end of file +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs index 687ec6ab9eb..f68f688d513 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs @@ -68,7 +68,8 @@ public static Mock LoadMockGenerator( HttpMessageApi? httpMessageApi = null, RequestContentApi? requestContentApi = null, Func? auth = null, - bool includeXmlDocs = false) + bool includeXmlDocs = false, + Func? createCSharpTypeCoreFallback = null) { IReadOnlyList inputNsApiVersions = apiVersions?.Invoke() ?? []; IReadOnlyList inputNsLiterals = inputLiterals?.Invoke() ?? []; @@ -110,7 +111,19 @@ public static Mock LoadMockGenerator( if (createCSharpTypeCore is not null) { - mockTypeFactory.Protected().Setup("CreateCSharpTypeCore", ItExpr.IsAny()).Returns(createCSharpTypeCore); + if (createCSharpTypeCoreFallback is not null) + { + mockTypeFactory.Protected() + .Setup("CreateCSharpTypeCore", ItExpr.IsAny()) + .Returns((InputType input) => + createCSharpTypeCoreFallback(input) + ? createCSharpTypeCore(input) + : null!); + } + else + { + mockTypeFactory.Protected().Setup("CreateCSharpTypeCore", ItExpr.IsAny()).Returns(createCSharpTypeCore); + } } if (createClientCore is not null) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj index 44f0f8602d8..2923ecb6971 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj @@ -2,7 +2,9 @@ + + diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs new file mode 100644 index 00000000000..45fa669af3d --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/ModelReaderWriterContextDefinitionBenchmark.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using BenchmarkDotNet.Attributes; +using Microsoft.TypeSpec.Generator.ClientModel.Providers; +using Microsoft.TypeSpec.Generator.ClientModel.Tests; +using Microsoft.TypeSpec.Generator.Input; +using Microsoft.TypeSpec.Generator.Statements; +using Microsoft.TypeSpec.Generator.Tests.Common; + +namespace Microsoft.TypeSpec.Generator.ClientModel.Perf +{ + [MemoryDiagnoser] + public class ModelReaderWriterContextDefinitionBenchmark + { + private ModelReaderWriterContextDefinition? _contextDefinition; + private Func>? _privateDelegate; + + [Params(1, 10, 100)] + public int ModelCount; + + [Params(1, 10, 100)] + public int SimplePropertyCount; + + [Params(0, 1, 2, 5)] + public int NestingLevel; + + [GlobalSetup] + public void Setup() + { + var generator = MockHelpers.LoadMockGenerator(inputModels: () => GetMockModels(ModelCount, SimplePropertyCount, NestingLevel)); + + _contextDefinition = generator.Object.OutputLibrary.TypeProviders.OfType().FirstOrDefault(); + + var methodInfo = typeof(ModelReaderWriterContextDefinition).GetMethod("BuildAttributes", BindingFlags.Instance | BindingFlags.NonPublic); + _privateDelegate = CreateDelegate>>(methodInfo!); + } + + [GlobalCleanup] + public void Cleanup() + { + _contextDefinition = null; + } + + [Benchmark] + public IReadOnlyList CollectBuildableTypes() + { + return _privateDelegate!(_contextDefinition!); + } + + private IReadOnlyList GetMockModels(int modelCount, int simplePropertyCount, int nestingLevel) + { + return + [ + .. GetSimpleModels(modelCount, simplePropertyCount, nestingLevel), + ]; + } + + private static IEnumerable GetSimpleModels(int modelCount, int simplePropertyCount, int nestingLevel) + { + for (int i = 0; i < modelCount; i++) + { + yield return GetNestedModel(i, simplePropertyCount, nestingLevel); + } + } + + private static IEnumerable GetSimpleProperties(int simplePropertyCount) + { + for (int i = 0; i < simplePropertyCount; i++) + { + yield return InputFactory.Property($"Property{i}", InputPrimitiveType.String, isRequired: true); + } + } + + private static InputModelType GetNestedModel(int modelNumber, int simplePropertyCount, int nestingLevel) + { + var nestedModel = GetRecursiveNestedModel(modelNumber, simplePropertyCount, nestingLevel); + return InputFactory.Model( + $"Model{modelNumber}", + properties: nestedModel is null + ? [.. GetSimpleProperties(simplePropertyCount)] + : [.. GetSimpleProperties(simplePropertyCount), InputFactory.Property($"Property{simplePropertyCount}", nestedModel)]); + } + + private static InputModelType? GetRecursiveNestedModel(int modelNumber, int simplePropertyCount, int nestingLevel) + { + if (nestingLevel <= 0) + return null; + + var nestedModel = GetRecursiveNestedModel(modelNumber, simplePropertyCount, nestingLevel - 1); + return InputFactory.Model( + $"NestedModel{modelNumber}_{nestingLevel}", + properties: nestedModel is null + ? [.. GetSimpleProperties(simplePropertyCount)] + : [.. GetSimpleProperties(simplePropertyCount), InputFactory.Property($"Property{simplePropertyCount}", nestedModel)]); + } + + private static T CreateDelegate(MethodInfo methodInfo) + { + var instanceParam = Expression.Parameter(typeof(object), "target"); + var parameters = methodInfo.GetParameters() + .Select(p => Expression.Parameter(p.ParameterType, p.Name)) + .ToArray(); + + var instanceCast = Expression.Convert(instanceParam, methodInfo.DeclaringType!); + var methodCall = Expression.Call(instanceCast, methodInfo, parameters); + + var lambdaParams = new ParameterExpression[] { instanceParam }.Concat(parameters); + var lambda = Expression.Lambda(methodCall, lambdaParams); + + return lambda.Compile(); + } + } +} From fd1eb6519244762c4f807d7ae3fbcb9f2a56c3b9 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Fri, 18 Jul 2025 16:22:40 -0700 Subject: [PATCH 21/21] regen --- .../multipart/src/Generated/Models/PayloadMultiPartContext.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs index 390c801869d..3ea74bcd753 100644 --- a/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs +++ b/packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Generated/Models/PayloadMultiPartContext.cs @@ -3,8 +3,6 @@ #nullable disable using System.ClientModel.Primitives; -using Payload.MultiPart._FormData; -using Payload.MultiPart._FormData.HttpParts.NonString; namespace Payload.MultiPart {