Skip to content

Commit

Permalink
change the array to IReadOnlyList since it is a public API (#3418)
Browse files Browse the repository at this point in the history
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<>`
  • Loading branch information
ArcturusZhang authored May 22, 2024
1 parent fb40300 commit ffaff36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,10 +30,10 @@ public class ClientModelPlugin : CodeModelPlugin
/// Returns the serialization type providers for the given model type provider.
/// </summary>
/// <param name="provider">The model type provider.</param>
public override TypeProvider[] GetSerializationTypeProviders(ModelTypeProvider provider)
public override IReadOnlyList<TypeProvider> GetSerializationTypeProviders(ModelTypeProvider provider)
{
// Add JSON serialization type provider
return new TypeProvider[] { new MrwSerializationTypeProvider(provider) };
return [new MrwSerializationTypeProvider(provider)];
}

[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +44,6 @@ public CodeModelPlugin(GeneratorContext context)
/// Returns a serialization type provider for the given model type provider.
/// </summary>
/// <param name="provider">The model type provider.</param>
public abstract TypeProvider[] GetSerializationTypeProviders(ModelTypeProvider provider);
public abstract IReadOnlyList<TypeProvider> GetSerializationTypeProviders(ModelTypeProvider provider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class ModelTypeProvider : TypeProvider
/// <summary>
/// The serializations providers for the model provider.
/// </summary>
public TypeProvider[] SerializationProviders { get; } = Array.Empty<TypeProvider>();
public IReadOnlyList<TypeProvider> SerializationProviders { get; } = Array.Empty<TypeProvider>();

public ModelTypeProvider(InputModelType inputModel, SourceInputModel? sourceInputModel)
: base(sourceInputModel)
Expand Down

0 comments on commit ffaff36

Please sign in to comment.