Skip to content

Extend struct-typed constants onto their struct under extensionReceiver - #1743

Merged
Jevan Saks (jevansaks) merged 1 commit into
microsoft:mainfrom
JeremyKuhne:extensionReceiver-struct-constants
Jul 14, 2026
Merged

Extend struct-typed constants onto their struct under extensionReceiver#1743
Jevan Saks (jevansaks) merged 1 commit into
microsoft:mainfrom
JeremyKuhne:extensionReceiver-struct-constants

Conversation

@JeremyKuhne

Copy link
Copy Markdown
Member

When extensionReceiver is configured, a constant typed as a typedef struct (HRESULT, NTSTATUS, HWND, BOOL, HKEY, ...) whose struct is owned by a referenced assembly is now attached to that struct through a C# 14 extension(<Struct>) block, so it reads as <Struct>.<Name> -- matching how the owning assembly surfaces its own constants of that type. Previously these constants only reached the host constants class.

Details:

  • Decoupled from receiver resolvability: a cross-namespace extender whose own receiver (e.g. Windows.Wdk.PInvoke) does not resolve still attaches constants to a resolvable struct such as Windows.Win32.Foundation.NTSTATUS.

  • When the struct is generated in the same assembly it is injected directly as before (no extension block).

  • Deduped against the struct's existing members so a lower layer that already exposes the constant is not duplicated.

  • Silent fallback to the host class when the struct is not in any referenced assembly.

Adds unit tests (attach-to-struct-not-receiver, dedup, local-injection-unchanged, compiles-under-C#14) and documents the behavior in composition.md.

When `extensionReceiver` is configured, a constant typed as a typedef struct (HRESULT, NTSTATUS, HWND, BOOL, HKEY, ...) whose struct is owned by a referenced assembly is now attached to that struct through a C# 14 `extension(<Struct>)` block, so it reads as `<Struct>.<Name>` -- matching how the owning assembly surfaces its own constants of that type. Previously these constants only reached the host constants class.

Details:

* Decoupled from receiver resolvability: a cross-namespace extender whose own receiver (e.g. Windows.Wdk.PInvoke) does not resolve still attaches constants to a resolvable struct such as Windows.Win32.Foundation.NTSTATUS.

* When the struct is generated in the same assembly it is injected directly as before (no extension block).

* Deduped against the struct's existing members so a lower layer that already exposes the constant is not duplicated.

* Silent fallback to the host class when the struct is not in any referenced assembly.

Adds unit tests (attach-to-struct-not-receiver, dedup, local-injection-unchanged, compiles-under-C#14) and documents the behavior in composition.md.
@jevansaks
Jevan Saks (jevansaks) merged commit bc7c37c into microsoft:main Jul 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants