diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/TypeProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/TypeProvider.cs index 8ddc2df301..aff1fd9f22 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/TypeProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/TypeProvider.cs @@ -425,7 +425,7 @@ private static bool IsMatch(MethodSignatureBase customMethod, MethodSignatureBas for (int i = 0; i < customMethod.Parameters.Count; i++) { - if (customMethod.Parameters[i].Type.Name != method.Parameters[i].Type.Name) + if (!customMethod.Parameters[i].Type.Name.EndsWith(method.Parameters[i].Type.Name)) { return false; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ModelCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ModelCustomizationTests.cs index 3a493ac1d5..348fbf4813 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ModelCustomizationTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ModelCustomizationTests.cs @@ -329,23 +329,30 @@ await MockHelpers.LoadMockPluginAsync( [Test] public async Task CanReplaceConstructor() { + var subModel = InputFactory.Model( + "subModel", + usage: InputModelTypeUsage.Input, + properties: new[] { InputFactory.Property("SubProperty", InputPrimitiveType.Int32) }); + var plugin = await MockHelpers.LoadMockPluginAsync( inputModelTypes: new[] { InputFactory.Model( "mockInputModel", // use Input so that we generate a public ctor usage: InputModelTypeUsage.Input, - properties: new[] { InputFactory.Property("Prop1", InputPrimitiveType.String) }) + properties: new[] + { + InputFactory.Property("Prop1", InputPrimitiveType.String), + InputFactory.Property("SubModel", subModel) + }) }, compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); var csharpGen = new CSharpGen(); await csharpGen.ExecuteAsync(); - // The generated code should only contain the single internal ctor containing the properties - var ctor = plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputModel").Constructors.Single(); - Assert.IsTrue(ctor.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Internal)); - Assert.AreEqual("prop1", ctor.Signature.Parameters.First().Name); + // The generated code should not contain any ctors + Assert.IsEmpty(plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputModel").Constructors); } [Test] diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReplaceConstructor/MockInputModel.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReplaceConstructor/MockInputModel.cs index 9c08aa319a..38c76e3fe8 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReplaceConstructor/MockInputModel.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReplaceConstructor/MockInputModel.cs @@ -7,4 +7,12 @@ public partial class MockInputModel internal MockInputModel() { } + + internal MockInputModel(string prop1, SubModel? subModel, IDictionary serializedAdditionalRawData) + { + } +} + +public readonly partial struct SubModel +{ }