Skip to content

Centralize C# type attribute back-compat merging in TypeProvider - #11237

Closed
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 47 commits into
mainfrom
copilot/centralize-type-attribute-merging
Closed

Centralize C# type attribute back-compat merging in TypeProvider#11237
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 47 commits into
mainfrom
copilot/centralize-type-attribute-merging

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Attribute back-compat merging (generated + last-contract + custom-code) was owned locally by CanonicalTypeProvider.BuildAttributes(). This moves that logic into a shared TypeProvider API so it follows the existing centralized back-compat pattern (Build*ForBackCompatibility).

Changes

  • TypeProvider: Added BuildAttributesForBackCompatibility() that:
    • restores compatible attributes from the last contract
    • merges generated (Attributes) and custom-code (CustomCodeView.Attributes) attributes,
    • filters CodeGen-specific attributes (CodeGenSuppress/CodeGenMember/CodeGenType/CodeGenSerialization) that should not be preserved,
    • deduplicates by rendered display string.
  • CanonicalTypeProvider: BuildAttributes() now delegates to the shared API instead of owning merge/dedup logic.
  • Tests: Added coverage for the merge/dedup behavior.

Because the method reads Attributes, CustomCodeView, LastContractView, and DeclarationModifiers from the provider, invoking it on the generated provider reproduces the previous merge exactly:

protected override IReadOnlyList<MethodBodyStatement> BuildAttributes()
    => _generatedTypeProvider.BuildAttributesForBackCompatibility();

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jul 13, 2026
Copilot AI and others added 2 commits July 13, 2026 20:37
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Centralize type attribute back-compat merging in C# generator Centralize C# type attribute back-compat merging in TypeProvider Jul 13, 2026
Copilot AI and others added 2 commits July 13, 2026 21:03
… attributes, perf

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11237

commit: 62d369e

…p internalize gating, add tests

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…tions

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI and others added 4 commits July 20, 2026 16:07
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI and others added 2 commits July 20, 2026 16:16
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@jorgerangel-msft

Copy link
Copy Markdown
Contributor

Copilot pull latest main

…pe-attribute-merging

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Copilot pull latest main

Addressed in db06b4a1. I pulled the latest main into this branch, validated the http-client-csharp build, reran the targeted TypeProviderTests and ScmModelProviderTests, and npm run cop passed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot pull latest main and address merge conflicts

…pe-attribute-merging

# Conflicts:
#	packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ModelReaderWriterContextDefinition.cs
#	packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestHelpers/MockHelpers.cs

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Copilot pull latest main and address merge conflicts

Addressed in 03978c040. I pulled the latest main, resolved the merge conflicts in ModelReaderWriterContextDefinition.cs and MockHelpers.cs, and revalidated with npm run build, both generator test suites, and npm run cop.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
{
public static class CodeGenAttributes
{
public const string CodeGenAttributePrefix = "CodeGen";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot why do we still have this? Remove this change and all of the obsolete code we have

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI and others added 3 commits July 23, 2026 21:35
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding attributes to the list of supported backcompat scenarios

3 participants