From ffaff36bfab8e0808ac267a405d4006cbfd2b3a0 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Thu, 23 May 2024 00:27:01 +0800 Subject: [PATCH] change the array to `IReadOnlyList` since it is a public API (#3418) Since the `GetSerializationTypeProviders` is a public API and we never except the consumer of this method to modify the returned values, we should return it in a `IReadOnlyList<>` --- .../src/ClientModelPlugin.cs | 6 +++--- .../Microsoft.Generator.CSharp/src/CodeModelPlugin.cs | 3 ++- .../src/OutputTypes/ModelTypeProvider.cs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs index 29a304720e..ae60ddbf62 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs @@ -2,10 +2,10 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.ComponentModel.Composition; using Microsoft.Generator.CSharp.ClientModel.Expressions; using Microsoft.Generator.CSharp.Expressions; -using Microsoft.Generator.CSharp.Input; using Microsoft.Generator.CSharp.Writers; namespace Microsoft.Generator.CSharp.ClientModel @@ -30,10 +30,10 @@ public class ClientModelPlugin : CodeModelPlugin /// Returns the serialization type providers for the given model type provider. /// /// The model type provider. - public override TypeProvider[] GetSerializationTypeProviders(ModelTypeProvider provider) + public override IReadOnlyList GetSerializationTypeProviders(ModelTypeProvider provider) { // Add JSON serialization type provider - return new TypeProvider[] { new MrwSerializationTypeProvider(provider) }; + return [new MrwSerializationTypeProvider(provider)]; } [ImportingConstructor] diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/CodeModelPlugin.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/CodeModelPlugin.cs index 1548acb336..8f0ab7cb23 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/CodeModelPlugin.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/CodeModelPlugin.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.ComponentModel.Composition; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Input; @@ -43,6 +44,6 @@ public CodeModelPlugin(GeneratorContext context) /// Returns a serialization type provider for the given model type provider. /// /// The model type provider. - public abstract TypeProvider[] GetSerializationTypeProviders(ModelTypeProvider provider); + public abstract IReadOnlyList GetSerializationTypeProviders(ModelTypeProvider provider); } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/OutputTypes/ModelTypeProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/OutputTypes/ModelTypeProvider.cs index 47d76fb640..5c3660a55b 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/OutputTypes/ModelTypeProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/OutputTypes/ModelTypeProvider.cs @@ -18,7 +18,7 @@ public sealed class ModelTypeProvider : TypeProvider /// /// The serializations providers for the model provider. /// - public TypeProvider[] SerializationProviders { get; } = Array.Empty(); + public IReadOnlyList SerializationProviders { get; } = Array.Empty(); public ModelTypeProvider(InputModelType inputModel, SourceInputModel? sourceInputModel) : base(sourceInputModel)