From da0fbc23b2bb8091f9e93346c3911be4897c1ea6 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:57:33 -0700 Subject: [PATCH] Add support for suppressing members (#4479) Fixes https://github.com/microsoft/typespec/issues/4446 --- .../src/CodeModelPlugin.cs | 2 +- .../src/MemberRemoverVisitor.cs | 157 ++++++++++++ .../src/Providers/NamedTypeSymbolProvider.cs | 2 + .../src/Providers/TypeProvider.cs | 3 + .../test/PluginTests.cs | 3 +- .../ClientCustomizationTests.cs | 227 ++++++++++++++++++ .../ModelProviders/ModelCustomizationTests.cs | 21 +- .../CanRemoveConstructors/MockInputClient.cs | 11 + .../CanRemoveMethods/MockInputClient.cs | 11 + .../MockInputClient.cs | 9 + .../MockInputClient.cs | 10 + .../CanRemoveProperty/MockInputModel.cs | 8 + 12 files changed, 459 insertions(+), 5 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/MemberRemoverVisitor.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ClientCustomizationTests.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveConstructors/MockInputClient.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveMethods/MockInputClient.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveConstructorsThatDoNotMatch/MockInputClient.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveMethodsThatDoNotMatch/MockInputClient.cs create mode 100644 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRemoveProperty/MockInputModel.cs 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 89c9283468..e46237da52 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 @@ -21,7 +21,7 @@ namespace Microsoft.Generator.CSharp [ExportMetadata("PluginName", nameof(CodeModelPlugin))] public abstract class CodeModelPlugin { - private List _visitors = new(); + private List _visitors = [new MemberRemoverVisitor()]; private static CodeModelPlugin? _instance; internal static CodeModelPlugin Instance { diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/MemberRemoverVisitor.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/MemberRemoverVisitor.cs new file mode 100644 index 0000000000..8aa3bec639 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/MemberRemoverVisitor.cs @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.Generator.CSharp.Primitives; +using Microsoft.Generator.CSharp.Providers; +using Microsoft.Generator.CSharp.SourceInput; + +namespace Microsoft.Generator.CSharp +{ + internal class MemberRemoverVisitor : LibraryVisitor + { + protected override MethodProvider? Visit(MethodProvider methodProvider) + { + foreach (var attribute in GetMemberSuppressionAttributes(methodProvider.EnclosingType)) + { + if (ShouldRemove(methodProvider.EnclosingType, methodProvider.Signature, attribute)) + { + return null; + } + } + + return methodProvider; + } + + protected override ConstructorProvider? Visit(ConstructorProvider constructorProvider) + { + foreach (var attribute in GetMemberSuppressionAttributes(constructorProvider.EnclosingType)) + { + if (ShouldRemove(constructorProvider.EnclosingType, constructorProvider.Signature, attribute)) + { + return null; + } + } + + return constructorProvider; + } + + protected override PropertyProvider? Visit(PropertyProvider propertyProvider) + { + foreach (var attribute in GetMemberSuppressionAttributes(propertyProvider.EnclosingType)) + { + if (ShouldRemove(propertyProvider, attribute)) + { + return null; + } + } + + return propertyProvider; + } + + private static IEnumerable GetMemberSuppressionAttributes(TypeProvider typeProvider) + => typeProvider.CustomCodeView?.GetAttributes()?.Where(a => a.AttributeClass?.Name == CodeGenAttributes.CodeGenSuppressAttributeName) ?? []; + + private static bool ShouldRemove(TypeProvider enclosingType, MethodSignatureBase signature, AttributeData attribute) + { + ValidateArguments(enclosingType, attribute); + var name = attribute.ConstructorArguments[0].Value as string; + if (name != signature.Name) + { + return false; + } + + ISymbol?[]? parameterTypes; + if (attribute.ConstructorArguments.Length == 1) + { + parameterTypes = []; + } + else if (attribute.ConstructorArguments[1].Kind != TypedConstantKind.Array) + { + parameterTypes = [(ISymbol?) attribute.ConstructorArguments[1].Value]; + } + else + { + parameterTypes = attribute.ConstructorArguments[1].Values.Select(v => (ISymbol?)v.Value).ToArray(); + } + if (parameterTypes.Length != signature.Parameters.Count) + { + return false; + } + + for (int i = 0; i < parameterTypes.Length; i++) + { + if (parameterTypes[i]?.Name != signature.Parameters[i].Type.Name) + { + return false; + } + } + + return true; + } + + private static bool ShouldRemove(PropertyProvider propertyProvider, AttributeData attribute) + { + ValidateArguments(propertyProvider.EnclosingType, attribute); + var name = attribute.ConstructorArguments[0].Value as string; + return name == propertyProvider.Name; + } + + private static void ValidateArguments(TypeProvider type, AttributeData attributeData) + { + var arguments = attributeData.ConstructorArguments; + if (arguments.Length == 0) + { + throw new InvalidOperationException($"CodeGenSuppress attribute on {type.Name} must specify a method, constructor, or property name as its first argument."); + } + + if (arguments[0].Kind != TypedConstantKind.Primitive || arguments[0].Value is not string) + { + var attribute = GetText(attributeData.ApplicationSyntaxReference); + throw new InvalidOperationException($"{attribute} attribute on {type.Name} must specify a method, constructor, or property name as its first argument."); + } + + if (arguments.Length == 2 && arguments[1].Kind == TypedConstantKind.Array) + { + ValidateTypeArguments(type, attributeData, arguments[1].Values); + } + else + { + ValidateTypeArguments(type, attributeData, arguments.Skip(1)); + } + } + + private static void ValidateTypeArguments(TypeProvider type, AttributeData attributeData, IEnumerable arguments) + { + foreach (var argument in arguments) + { + if (argument.Kind == TypedConstantKind.Type) + { + if (argument.Value is IErrorTypeSymbol errorType) + { + var attribute = GetText(attributeData.ApplicationSyntaxReference); + var fileLinePosition = GetFileLinePosition(attributeData.ApplicationSyntaxReference); + var filePath = fileLinePosition.Path; + var line = fileLinePosition.StartLinePosition.Line + 1; + throw new InvalidOperationException($"The undefined type '{errorType.Name}' is referenced in the '{attribute}' attribute ({filePath}, line: {line}). Please define this type or remove it from the attribute."); + } + } + else + { + var attribute = GetText(attributeData.ApplicationSyntaxReference); + throw new InvalidOperationException($"Argument '{argument.ToCSharpString()}' in attribute '{attribute}' applied to '{type.Name}' must be a type."); + } + } + } + + private static string GetText(SyntaxReference? syntaxReference) + => syntaxReference?.SyntaxTree.GetText().ToString(syntaxReference.Span) ?? string.Empty; + + private static FileLinePositionSpan GetFileLinePosition(SyntaxReference? syntaxReference) + => syntaxReference?.SyntaxTree.GetLocation(syntaxReference.Span).GetLineSpan() ?? default; + } +} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/NamedTypeSymbolProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/NamedTypeSymbolProvider.cs index f0adaecf01..12c937ef6c 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/NamedTypeSymbolProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/NamedTypeSymbolProvider.cs @@ -165,6 +165,8 @@ protected override MethodProvider[] BuildMethods() protected override CSharpType BuildEnumUnderlyingType() => GetIsEnum() ? new CSharpType(typeof(int)) : throw new InvalidOperationException("This type is not an enum"); + internal override IEnumerable GetAttributes() => _namedTypeSymbol.GetAttributes(); + private ParameterProvider ConvertToParameterProvider(IMethodSymbol methodSymbol, IParameterSymbol parameterSymbol) { return new ParameterProvider( 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 e8e608cb3f..1fcc6b04bd 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 @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.CodeAnalysis; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; using Microsoft.Generator.CSharp.Statements; @@ -24,6 +25,8 @@ protected TypeProvider() public TypeProvider? CustomCodeView => _customCodeView.Value; + internal virtual IEnumerable? GetAttributes() => null; + protected string? _deprecated; /// diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/PluginTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/PluginTests.cs index baaec25b2b..4b4dfd7b3e 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/PluginTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/PluginTests.cs @@ -13,7 +13,8 @@ public void CanAddVisitors() { var plugin = new TestPlugin(); plugin.AddVisitor(new TestLibraryVisitor()); - Assert.AreEqual(1, plugin.Visitors.Count); + // There is 1 default visitor added by the generator. + Assert.AreEqual(2, plugin.Visitors.Count); } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ClientCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ClientCustomizationTests.cs new file mode 100644 index 0000000000..90e7c409de --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/ClientCustomizationTests.cs @@ -0,0 +1,227 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Generator.CSharp.Primitives; +using Microsoft.Generator.CSharp.Providers; +using Microsoft.Generator.CSharp.Snippets; +using NUnit.Framework; + +namespace Microsoft.Generator.CSharp.Tests.Providers.ModelProviders +{ + public class ClientCustomizationTests + { + [Test] + public async Task CanRemoveMethods() + { + var client = new ClientTypeProvider(); + var methods = new[] + { + new MethodProvider(new MethodSignature( + "Method1", + $"", + MethodSignatureModifiers.Public, + null, + $"", + []), + Snippet.ThrowExpression(Snippet.Null), client), + new MethodProvider(new MethodSignature( + "Method2", + $"", + MethodSignatureModifiers.Public, + null, + $"", + [ + new ParameterProvider("param1", $"", typeof(bool)) + ]), + Snippet.ThrowExpression(Snippet.Null), client), + new MethodProvider(new MethodSignature( + "Method3", + $"", + MethodSignatureModifiers.Public, + null, + $"", + [ + new ParameterProvider("param1", $"", typeof(string)), + new ParameterProvider("param2", $"", typeof(int))]), + Snippet.ThrowExpression(Snippet.Null), client) + + }; + client.MethodProviders = methods; + var outputLibrary = new ClientOutputLibrary(client); + + var plugin = await MockHelpers.LoadMockPluginAsync( + createOutputLibrary: () => outputLibrary, + compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + var csharpGen = new CSharpGen(); + await csharpGen.ExecuteAsync(); + + Assert.AreEqual(0, plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputClient").Methods.Count); + } + + [Test] + public async Task DoesNotRemoveMethodsThatDoNotMatch() + { + var client = new ClientTypeProvider(); + var methods = new[] + { + // Method name doesn't match + new MethodProvider(new MethodSignature( + "MethodA", + $"", + MethodSignatureModifiers.Public, + null, + $"", + []), + Snippet.ThrowExpression(Snippet.Null), client), + // Parameter type doesn't match + new MethodProvider(new MethodSignature( + "Method2", + $"", + MethodSignatureModifiers.Public, + null, + $"", + [ + new ParameterProvider("param1", $"", typeof(int)) + ]), + Snippet.ThrowExpression(Snippet.Null), client), + // Number of parameters doesn't match + new MethodProvider(new MethodSignature( + "Method3", + $"", + MethodSignatureModifiers.Public, + null, + $"", + [ + new ParameterProvider("param1", $"", typeof(string)), + new ParameterProvider("param2", $"", typeof(int))]), + Snippet.ThrowExpression(Snippet.Null), client) + + }; + client.MethodProviders = methods; + var outputLibrary = new ClientOutputLibrary(client); + + var plugin = await MockHelpers.LoadMockPluginAsync( + createOutputLibrary: () => outputLibrary, + compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + var csharpGen = new CSharpGen(); + await csharpGen.ExecuteAsync(); + + Assert.AreEqual(3, plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputClient").Methods.Count); + } + + [Test] + public async Task CanRemoveConstructors() + { + var client = new ClientTypeProvider(); + + var outputLibrary = new ClientOutputLibrary(client); + var plugin = await MockHelpers.LoadMockPluginAsync( + createOutputLibrary: () => outputLibrary, + compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + + var constructors = new[] + { + // Parameter type doesn't match + new ConstructorProvider(new ConstructorSignature( + new CSharpType(client, "Samples", [typeof(int)], null), + $"", + MethodSignatureModifiers.Public, + [new ParameterProvider("param1", $"", typeof(bool))]), + Snippet.ThrowExpression(Snippet.Null), client), + // Number of parameters doesn't match + new ConstructorProvider(new ConstructorSignature( + new CSharpType(client, "Samples", [typeof(int)], null), + $"", + MethodSignatureModifiers.Public, + [ + new ParameterProvider("param1", $"", typeof(bool)), + new ParameterProvider("param2", $"", typeof(int)), + ]), + Snippet.ThrowExpression(Snippet.Null), client) + }; + client.ConstructorProviders = constructors; + + var csharpGen = new CSharpGen(); + await csharpGen.ExecuteAsync(); + + Assert.AreEqual(0, plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputClient").Constructors.Count); + } + + [Test] + public async Task DoesNotRemoveConstructorsThatDoNotMatch() + { + var client = new ClientTypeProvider(); + + var outputLibrary = new ClientOutputLibrary(client); + var plugin = await MockHelpers.LoadMockPluginAsync( + createOutputLibrary: () => outputLibrary, + compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + + var constructors = new[] + { + new ConstructorProvider(new ConstructorSignature( + new CSharpType(client, "Samples", [typeof(int)], null), + $"", + MethodSignatureModifiers.Public, + []), + Snippet.ThrowExpression(Snippet.Null), client), + new ConstructorProvider(new ConstructorSignature( + new CSharpType(client, "Samples", [typeof(int)], null), + $"", + MethodSignatureModifiers.Public, + [new ParameterProvider("param1", $"", typeof(bool))]), + Snippet.ThrowExpression(Snippet.Null), client), + new ConstructorProvider(new ConstructorSignature( + new CSharpType(client, "Samples", [typeof(int)], null), + $"", + MethodSignatureModifiers.Public, + [ + new ParameterProvider("param1", $"", typeof(bool)), + new ParameterProvider("param2", $"", typeof(int)), + ]), + Snippet.ThrowExpression(Snippet.Null), client) + }; + client.ConstructorProviders = constructors; + + var csharpGen = new CSharpGen(); + await csharpGen.ExecuteAsync(); + + Assert.AreEqual(3, plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputClient").Constructors.Count); + } + + private class ClientOutputLibrary : OutputLibrary + { + private readonly ClientTypeProvider _client; + + public ClientOutputLibrary(ClientTypeProvider client) : base() + { + _client = client; + } + protected override TypeProvider[] BuildTypeProviders() + { + var providers = base.BuildTypeProviders(); + return + [ + .. providers, + _client + ]; + } + } + + private class ClientTypeProvider : TypeProvider + { + public MethodProvider[] MethodProviders { get; set; } = []; + public ConstructorProvider[] ConstructorProviders { get; set; } = []; + + protected override string BuildRelativeFilePath() => "."; + + protected override string BuildName() => "MockInputClient"; + + protected override MethodProvider[] BuildMethods() => MethodProviders; + + protected override ConstructorProvider[] BuildConstructors() => ConstructorProviders; + } + } +} 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 6aa064b5d3..f29af6a4b1 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 @@ -150,7 +150,7 @@ public async Task CanChangeModelNameAndToStructAtSameTime() Assert.AreEqual("NewNamespace.Models", modelTypeProvider.Type.Namespace); } - [TestCase] + [Test] public async Task CanChangeAccessibility() { await MockHelpers.LoadMockPluginAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); @@ -166,7 +166,7 @@ public async Task CanChangeAccessibility() Assert.IsFalse(modelTypeProvider.Type.IsPublic); } - [TestCase] + [Test] public async Task CanChangeEnumToExtensibleEnum() { await MockHelpers.LoadMockPluginAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); @@ -183,7 +183,7 @@ public async Task CanChangeEnumToExtensibleEnum() Assert.IsTrue(enumProvider.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public | TypeSignatureModifiers.Partial | TypeSignatureModifiers.Struct | TypeSignatureModifiers.ReadOnly)); } - [TestCase] + [Test] public async Task CanChangeExtensibleEnumToEnum() { await MockHelpers.LoadMockPluginAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); @@ -243,5 +243,20 @@ public async Task CanAddProperties() Assert.AreEqual(MethodSignatureModifiers.Public, customCodeView.Properties[1].Modifiers); Assert.IsFalse(customCodeView.Properties[1].Body.HasSetter); } + + [Test] + public async Task CanRemoveProperty() + { + var plugin = await MockHelpers.LoadMockPluginAsync( + inputModelTypes: new[] { + InputFactory.Model("mockInputModel", properties: new[] { + InputFactory.Property("Prop1", InputPrimitiveType.String) + }) + }, + compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + var csharpGen = new CSharpGen(); + await csharpGen.ExecuteAsync(); + Assert.AreEqual(0, plugin.Object.OutputLibrary.TypeProviders.Single(t => t.Name == "MockInputModel").Properties.Count); + } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveConstructors/MockInputClient.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveConstructors/MockInputClient.cs new file mode 100644 index 0000000000..188a76318f --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveConstructors/MockInputClient.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Microsoft.Generator.CSharp.Customization; + +namespace Sample; + +[CodeGenSuppress("MockInputClient"] +[CodeGenSuppress("MockInputClient", typeof(bool))] +[CodeGenSuppress("MockInputClient", typeof(bool), typeof(int))] +public partial class MockInputClient +{ +} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveMethods/MockInputClient.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveMethods/MockInputClient.cs new file mode 100644 index 0000000000..65e9152519 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/CanRemoveMethods/MockInputClient.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Microsoft.Generator.CSharp.Customization; + +namespace Sample; + +[CodeGenSuppress("Method1")] +[CodeGenSuppress("Method2", typeof(bool)] +[CodeGenSuppress("Method3", typeof(string), typeof(int))] +public partial class MockInputClient +{ +} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveConstructorsThatDoNotMatch/MockInputClient.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveConstructorsThatDoNotMatch/MockInputClient.cs new file mode 100644 index 0000000000..5f794aad74 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveConstructorsThatDoNotMatch/MockInputClient.cs @@ -0,0 +1,9 @@ +using Microsoft.Generator.CSharp.Customization; + +namespace Sample; + +[CodeGenSuppress("MockInputClient", typeof(string)] +[CodeGenSuppress("MockInputClient", typeof(string), typeof(int), typeof(bool))] +public partial class MockInputClient +{ +} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveMethodsThatDoNotMatch/MockInputClient.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveMethodsThatDoNotMatch/MockInputClient.cs new file mode 100644 index 0000000000..550401ac55 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ClientCustomizationTests/DoesNotRemoveMethodsThatDoNotMatch/MockInputClient.cs @@ -0,0 +1,10 @@ +using Microsoft.Generator.CSharp.Customization; + +namespace Sample; + +[CodeGenSuppress("Method1")] +[CodeGenSuppress("Method2", typeof(bool)] +[CodeGenSuppress("Method3", typeof(string), typeof(int), typeof(bool))] +public partial class MockInputClient +{ +} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRemoveProperty/MockInputModel.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRemoveProperty/MockInputModel.cs new file mode 100644 index 0000000000..66007a9ee0 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRemoveProperty/MockInputModel.cs @@ -0,0 +1,8 @@ +using Microsoft.Generator.CSharp.Customization; + +namespace Sample.Models; + +[CodeGenSuppress("Prop1")] +public partial class MockInputModel +{ +}