Skip to content

Hide HasUnwrappableNativeObjectReference and IsOverridableInterface from reference projections#2371

Merged
Sergio0694 merged 2 commits intostaging/3.0from
dev/hide-abstract-members-from-ref-projections
Mar 27, 2026
Merged

Hide HasUnwrappableNativeObjectReference and IsOverridableInterface from reference projections#2371
Sergio0694 merged 2 commits intostaging/3.0from
dev/hide-abstract-members-from-ref-projections

Conversation

@Sergio0694
Copy link
Copy Markdown
Member

Summary

Hide HasUnwrappableNativeObjectReference and IsOverridableInterface from reference projections by making them virtual (instead of abstract) on WindowsRuntimeObject and skipping their codegen in cswinrt.exe for reference projection mode.

Motivation

These two members are private implementation details that only matter at app build time (when the actual projection implementations are generated). Reference projections don't need them — they exist solely to satisfy the abstract contract. By making the base class members virtual with an UnreachableException default, reference projections no longer need to emit dummy overrides, keeping their API surface cleaner and avoiding unnecessary code in distributed NuGet packages.

Changes

  • src/WinRT.Runtime2/WindowsRuntimeObject.cs: Change HasUnwrappableNativeObjectReference and IsOverridableInterface from abstract to virtual, with default implementations that throw UnreachableException
  • src/WinRT.Runtime2/Properties/WindowsRuntimeExceptionExtensions.cs: Add UnreachableException.Throw() helper following the existing extension pattern
  • src/cswinrt/code_writers.h: Skip generating HasUnwrappableNativeObjectReference and IsOverridableInterface overrides when settings.reference_projection is true

…rom reference projections

Change both members from abstract to virtual on WindowsRuntimeObject,
with default implementations that throw UnreachableException. Add a
new UnreachableException.Throw() helper in WindowsRuntimeExceptionExtensions.
Update cswinrt.exe to skip generating these overrides entirely when
producing reference projections.

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
@Sergio0694 Sergio0694 requested a review from manodasanW March 27, 2026 00:27
The type is no longer referenced by the code generator after the
previous change that removed the Obsolete/EditorBrowsable attributes
from generated reference projection overrides.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sergio0694 Sergio0694 enabled auto-merge (squash) March 27, 2026 03:34
@Sergio0694 Sergio0694 merged commit d009325 into staging/3.0 Mar 27, 2026
11 checks passed
@Sergio0694 Sergio0694 deleted the dev/hide-abstract-members-from-ref-projections branch March 27, 2026 17:46
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