From 241e002e3b4204d79c33609b1aaa5810a1c8d0b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 15:31:36 +0000 Subject: [PATCH 1/7] Initial plan From 596a43119d7b04c81e9a7c62d648880eed3a1253 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 15:39:31 +0000 Subject: [PATCH 2/7] fix: populate attributes from IPropertySymbol in NamedTypeSymbolProvider.BuildProperties Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/24b2dbde-3903-4684-830e-2b03e1d84dd2 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../src/Providers/NamedTypeSymbolProvider.cs | 3 ++- .../ModelProviders/ModelCustomizationTests.cs | 27 +++++++++++++++++++ .../MockInputModel.cs | 14 ++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs index eee24478749..f2ea3d050c0 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs @@ -146,7 +146,8 @@ protected internal override PropertyProvider[] BuildProperties() new AutoPropertyBody( propertySymbol.SetMethod is not null, InitializationExpression: GetPropertyInitializer(propertySymbol)), - this) + this, + attributes: propertySymbol.GetAttributes().Select(a => new AttributeStatement(a)).ToArray()) { OriginalName = GetOriginalName(propertySymbol), CustomProvider = new(() => propertySymbol.Type is INamedTypeSymbol propertyNamedTypeSymbol diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs index 556948c476e..04a4b85d6cf 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -1698,6 +1699,32 @@ public async Task CanCustomizeBaseModelToSystemType() "System.Exception is from a referenced assembly and should use SystemObjectTypeProvider"); } + [Test] + public async Task CanReadPropertyAttributes() + { + await MockHelpers.LoadMockGeneratorAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync()); + + var props = new[] + { + InputFactory.Property("Prop1", InputPrimitiveType.String) + }; + + var inputModel = InputFactory.Model("mockInputModel", properties: props); + var modelTypeProvider = new ModelProvider(inputModel); + var customCodeView = modelTypeProvider.CustomCodeView; + + Assert.IsNotNull(customCodeView); + Assert.AreEqual(1, customCodeView!.Properties.Count); + + var customProperty = customCodeView.Properties[0]; + Assert.AreEqual("Prop1", customProperty.Name); + + // Verify that attributes from custom code are populated + Assert.AreEqual(2, customProperty.Attributes.Count); + Assert.IsTrue(customProperty.Attributes.Any(a => a.Type.Name == nameof(ObsoleteAttribute))); + Assert.IsTrue(customProperty.Attributes.Any(a => a.Type.Name == "EditorBrowsableAttribute")); + } + private class TestNameVisitor : NameVisitor { public TypeProvider? InvokeVisit(TypeProvider type) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs new file mode 100644 index 00000000000..3c6f83d6c52 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs @@ -0,0 +1,14 @@ +#nullable disable + +using System; +using System.ComponentModel; + +namespace Sample.Models +{ + public partial class MockInputModel + { + [Obsolete("This property is now deprecated.")] + [EditorBrowsable(EditorBrowsableState.Never)] + public string Prop1 { get; set; } + } +} From 7afaec573aab6c8187419c6b92bd8b3369f33268 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 16:02:08 +0000 Subject: [PATCH 3/7] fix: also populate attributes for fields, improve tests with CSharpType.Equals, argument validation, and custom attribute Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1c0103ad-e7d0-4e76-b18f-12805d30824b Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../src/Providers/NamedTypeSymbolProvider.cs | 13 ++++++++-- .../ModelProviders/ModelCustomizationTests.cs | 24 +++++++++++++++---- .../MockInputModel.cs | 9 +++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs index f2ea3d050c0..ef7d6d3e6e9 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs @@ -122,7 +122,8 @@ protected internal override FieldProvider[] BuildFields() fieldSymbol.Name, this, GetSymbolXmlDoc(fieldSymbol, "summary"), - initializationValue: GetFieldInitializer(fieldSymbol)) + initializationValue: GetFieldInitializer(fieldSymbol), + attributes: GetAttributes(fieldSymbol)) { OriginalName = GetOriginalName(fieldSymbol) }; @@ -147,7 +148,7 @@ protected internal override PropertyProvider[] BuildProperties() propertySymbol.SetMethod is not null, InitializationExpression: GetPropertyInitializer(propertySymbol)), this, - attributes: propertySymbol.GetAttributes().Select(a => new AttributeStatement(a)).ToArray()) + attributes: GetAttributes(propertySymbol)) { OriginalName = GetOriginalName(propertySymbol), CustomProvider = new(() => propertySymbol.Type is INamedTypeSymbol propertyNamedTypeSymbol @@ -221,6 +222,14 @@ protected internal override PropertyProvider[] BuildProperties() return originalName; } + private static AttributeStatement[] GetAttributes(ISymbol symbol) + { + return symbol.GetAttributes() + .Where(a => a.AttributeClass?.ContainingNamespace?.ToDisplayString() != CodeModelGenerator.CustomizationAttributeNamespace) + .Select(a => new AttributeStatement(a)) + .ToArray(); + } + protected internal override ConstructorProvider[] BuildConstructors() { List constructors = new List(); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs index 04a4b85d6cf..dce953b98af 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs @@ -1719,10 +1719,26 @@ public async Task CanReadPropertyAttributes() var customProperty = customCodeView.Properties[0]; Assert.AreEqual("Prop1", customProperty.Name); - // Verify that attributes from custom code are populated - Assert.AreEqual(2, customProperty.Attributes.Count); - Assert.IsTrue(customProperty.Attributes.Any(a => a.Type.Name == nameof(ObsoleteAttribute))); - Assert.IsTrue(customProperty.Attributes.Any(a => a.Type.Name == "EditorBrowsableAttribute")); + // Verify that attributes from custom code are populated, including a custom non-system attribute + Assert.AreEqual(3, customProperty.Attributes.Count); + + // Validate [Obsolete("This property is now deprecated.")] - type and arguments + var obsoleteAttr = customProperty.Attributes.Single(a => new CSharpType(typeof(ObsoleteAttribute)).Equals(a.Type)); + Assert.AreEqual(1, obsoleteAttr.Arguments.Count); + + // Validate [EditorBrowsable(EditorBrowsableState.Never)] - type and arguments + var editorBrowsableAttr = customProperty.Attributes.Single(a => new CSharpType(typeof(System.ComponentModel.EditorBrowsableAttribute)).Equals(a.Type)); + Assert.AreEqual(1, editorBrowsableAttr.Arguments.Count); + + // Validate [Custom("custom message")] - custom non-system attribute does not throw + var customAttr = customProperty.Attributes.Single(a => a.Type.Name == "CustomAttribute"); + Assert.AreEqual(1, customAttr.Arguments.Count); + + // Verify that field attributes from custom code are populated + var customField = customCodeView.Fields.Single(f => f.Name == "_customField"); + Assert.AreEqual(1, customField.Attributes.Count); + var fieldObsoleteAttr = customField.Attributes.Single(a => new CSharpType(typeof(ObsoleteAttribute)).Equals(a.Type)); + Assert.AreEqual(1, fieldObsoleteAttr.Arguments.Count); } private class TestNameVisitor : NameVisitor diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs index 3c6f83d6c52..7c146c7ebb3 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs @@ -5,10 +5,19 @@ namespace Sample.Models { + public class CustomAttribute : Attribute + { + public CustomAttribute(string message) { } + } + public partial class MockInputModel { [Obsolete("This property is now deprecated.")] [EditorBrowsable(EditorBrowsableState.Never)] + [Custom("custom message")] public string Prop1 { get; set; } + + [Obsolete("This field is now deprecated.")] + private int _customField; } } From 259767f46261c4e615ce9ed9f9f4391ac8292538 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:24:55 +0000 Subject: [PATCH 4/7] fix: revert CodeGen attribute filtering, add PositionalArguments test, update expected output Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/96747ddb-cde5-4ed0-a8b9-27a2beaca6d3 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../CanCustomizePropertyUsingField.cs | 4 +++- .../src/Providers/NamedTypeSymbolProvider.cs | 12 ++---------- .../ModelProviders/ModelCustomizationTests.cs | 4 +++- .../CanReadPropertyAttributes/MockInputModel.cs | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs index b9088d85fa7..d774e69ab18 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using Microsoft.TypeSpec.Generator.Customizations; namespace Sample.Models { @@ -15,7 +16,8 @@ internal MockInputModel() { } - internal MockInputModel(string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) + internal MockInputModel([global::Microsoft.TypeSpec.Generator.Customizations.CodeGenMemberAttribute("Prop1")] + string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) { _myField = myField; _additionalBinaryDataProperties = additionalBinaryDataProperties; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs index ef7d6d3e6e9..699f97c788c 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs @@ -123,7 +123,7 @@ protected internal override FieldProvider[] BuildFields() this, GetSymbolXmlDoc(fieldSymbol, "summary"), initializationValue: GetFieldInitializer(fieldSymbol), - attributes: GetAttributes(fieldSymbol)) + attributes: fieldSymbol.GetAttributes().Select(a => new AttributeStatement(a)).ToArray()) { OriginalName = GetOriginalName(fieldSymbol) }; @@ -148,7 +148,7 @@ protected internal override PropertyProvider[] BuildProperties() propertySymbol.SetMethod is not null, InitializationExpression: GetPropertyInitializer(propertySymbol)), this, - attributes: GetAttributes(propertySymbol)) + attributes: propertySymbol.GetAttributes().Select(a => new AttributeStatement(a)).ToArray()) { OriginalName = GetOriginalName(propertySymbol), CustomProvider = new(() => propertySymbol.Type is INamedTypeSymbol propertyNamedTypeSymbol @@ -222,14 +222,6 @@ protected internal override PropertyProvider[] BuildProperties() return originalName; } - private static AttributeStatement[] GetAttributes(ISymbol symbol) - { - return symbol.GetAttributes() - .Where(a => a.AttributeClass?.ContainingNamespace?.ToDisplayString() != CodeModelGenerator.CustomizationAttributeNamespace) - .Select(a => new AttributeStatement(a)) - .ToArray(); - } - protected internal override ConstructorProvider[] BuildConstructors() { List constructors = new List(); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs index dce953b98af..7a98d5fbf4a 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs @@ -1722,9 +1722,11 @@ public async Task CanReadPropertyAttributes() // Verify that attributes from custom code are populated, including a custom non-system attribute Assert.AreEqual(3, customProperty.Attributes.Count); - // Validate [Obsolete("This property is now deprecated.")] - type and arguments + // Validate [Obsolete("This property is now deprecated.", DiagnosticId = "OBS001")] - type, arguments, and positional arguments var obsoleteAttr = customProperty.Attributes.Single(a => new CSharpType(typeof(ObsoleteAttribute)).Equals(a.Type)); Assert.AreEqual(1, obsoleteAttr.Arguments.Count); + Assert.AreEqual(1, obsoleteAttr.PositionalArguments.Count); + Assert.AreEqual("DiagnosticId", obsoleteAttr.PositionalArguments[0].Key); // Validate [EditorBrowsable(EditorBrowsableState.Never)] - type and arguments var editorBrowsableAttr = customProperty.Attributes.Single(a => new CSharpType(typeof(System.ComponentModel.EditorBrowsableAttribute)).Equals(a.Type)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs index 7c146c7ebb3..83e1984f82c 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanReadPropertyAttributes/MockInputModel.cs @@ -12,7 +12,7 @@ public CustomAttribute(string message) { } public partial class MockInputModel { - [Obsolete("This property is now deprecated.")] + [Obsolete("This property is now deprecated.", DiagnosticId = "OBS001")] [EditorBrowsable(EditorBrowsableState.Never)] [Custom("custom message")] public string Prop1 { get; set; } From 6ee954ca2c8edda8bd2ee5abfaf7d1c03af35ca8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:38:02 +0000 Subject: [PATCH 5/7] fix: revert expected output change and stop propagating field attributes to constructor parameters Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/2aa57a53-e9f5-4f62-b4a3-eafbe19db041 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../ModelCustomizationTests/CanCustomizePropertyUsingField.cs | 4 +--- .../src/Providers/FieldProvider.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs index d774e69ab18..b9088d85fa7 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using Microsoft.TypeSpec.Generator.Customizations; namespace Sample.Models { @@ -16,8 +15,7 @@ internal MockInputModel() { } - internal MockInputModel([global::Microsoft.TypeSpec.Generator.Customizations.CodeGenMemberAttribute("Prop1")] - string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) + internal MockInputModel(string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) { _myField = myField; _additionalBinaryDataProperties = additionalBinaryDataProperties; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs index cb411d1d53f..394b2a89547 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs @@ -148,7 +148,7 @@ public void Update( private void InitializeParameter() { _parameter = new(() => new ParameterProvider( - Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo, attributes: Attributes)); + Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo)); } private MemberExpression? _asMember; From 421fef110366ed6e3aff2ab674fbdfe41073145b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:56:57 +0000 Subject: [PATCH 6/7] fix: revert FieldProvider.InitializeParameter to propagate attributes to constructor parameters Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/52c392ca-eff3-412f-ad7b-8142cb7871b1 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../ModelCustomizationTests/CanCustomizePropertyUsingField.cs | 4 +++- .../src/Providers/FieldProvider.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs index b9088d85fa7..d774e69ab18 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using Microsoft.TypeSpec.Generator.Customizations; namespace Sample.Models { @@ -15,7 +16,8 @@ internal MockInputModel() { } - internal MockInputModel(string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) + internal MockInputModel([global::Microsoft.TypeSpec.Generator.Customizations.CodeGenMemberAttribute("Prop1")] + string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) { _myField = myField; _additionalBinaryDataProperties = additionalBinaryDataProperties; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs index 394b2a89547..cb411d1d53f 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs @@ -148,7 +148,7 @@ public void Update( private void InitializeParameter() { _parameter = new(() => new ParameterProvider( - Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo)); + Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo, attributes: Attributes)); } private MemberExpression? _asMember; From ecf9570cffe2730dcc71d5769b7eee48359fe056 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 19:05:59 +0000 Subject: [PATCH 7/7] fix: filter codegen attributes from field-to-parameter propagation in FieldProvider Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c117587e-318d-4500-a614-6f4388418265 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> --- .../ModelCustomizationTests/CanCustomizePropertyUsingField.cs | 4 +--- .../src/Providers/FieldProvider.cs | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs index d774e69ab18..b9088d85fa7 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using Microsoft.TypeSpec.Generator.Customizations; namespace Sample.Models { @@ -16,8 +15,7 @@ internal MockInputModel() { } - internal MockInputModel([global::Microsoft.TypeSpec.Generator.Customizations.CodeGenMemberAttribute("Prop1")] - string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) + internal MockInputModel(string myField, global::System.Collections.Generic.IDictionary additionalBinaryDataProperties) { _myField = myField; _additionalBinaryDataProperties = additionalBinaryDataProperties; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs index cb411d1d53f..fc218d46db1 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FieldProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; using Microsoft.TypeSpec.Generator.Expressions; using Microsoft.TypeSpec.Generator.Input.Extensions; using Microsoft.TypeSpec.Generator.Primitives; @@ -147,8 +148,9 @@ public void Update( [MemberNotNull(nameof(_parameter))] private void InitializeParameter() { + var paramAttributes = Attributes.Where(a => a.Type.Namespace != CodeModelGenerator.CustomizationAttributeNamespace).ToArray(); _parameter = new(() => new ParameterProvider( - Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo, attributes: Attributes)); + Name.ToVariableName(), Description ?? FormattableStringHelpers.Empty, Type, field: this, wireInfo: WireInfo, attributes: paramAttributes)); } private MemberExpression? _asMember;