Skip to content

Split WindowsRuntimeObject into a partial implementation file#2446

Merged
Sergio0694 merged 1 commit into
staging/winrt-runtime-ref-assemblyfrom
user/sergiopedri/split-windows-runtime-object
Jun 17, 2026
Merged

Split WindowsRuntimeObject into a partial implementation file#2446
Sergio0694 merged 1 commit into
staging/winrt-runtime-ref-assemblyfrom
user/sergiopedri/split-windows-runtime-object

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Splits the WindowsRuntimeObject base type into two partial files: WindowsRuntimeObject.cs keeps the type declaration and the public explicit interface implementations, while the new WindowsRuntimeObject.Impl.cs holds all of the implementation detail (backing fields, constructors, and methods). This is a pure code move with no behavior changes.

Motivation

This refactoring is a prerequisite for #2444 (Set up dual reference assembly build for WinRT.Runtime). Pulling it into its own PR keeps the diff for #2444 small and much easier to review: the move alone adds a large number of lines to the diff even though it only relocates existing code. #2444 will be rebased on top of this once it merges.

Changes

  • WindowsRuntimeObject.cs: reduced to the type declaration (now partial) and the explicit interface implementations for IDynamicInterfaceCastable, IUnmanagedVirtualMethodTableProvider, and ICustomQueryInterface, which forward to the implementation methods.
  • WindowsRuntimeObject.Impl.cs: new partial file containing the relocated implementation (backing fields, constructors, and all members).

Extract the bulk of WindowsRuntimeObject's implementation into a new partial file (WindowsRuntimeObject.Impl.cs) and update WindowsRuntimeObject.cs to be a partial declaration. The change relocates constructors, caching fields, dynamic cast/QueryInterface logic, virtual method table helpers, and exception stubs into the new file while removing now-unneeded usings from the original file. This refactor preserves existing behavior but improves code organization and maintainability by separating surface declaration from detailed implementation.
@Sergio0694 Sergio0694 added code cleanup Code cleanup and refactoring CsWinRT 3.0 labels Jun 17, 2026
@Sergio0694 Sergio0694 requested a review from manodasanW June 17, 2026 06:00
@Sergio0694 Sergio0694 merged commit 85ce997 into staging/winrt-runtime-ref-assembly Jun 17, 2026
11 checks passed
@Sergio0694 Sergio0694 deleted the user/sergiopedri/split-windows-runtime-object branch June 17, 2026 15:53
Sergio0694 added a commit that referenced this pull request Jun 17, 2026
…2448)

* Bring back WindowsRuntimeConstants for the WindowsRuntimeObject constructor

Re-add the type removed in #2434, now holding the dedicated obsolete message, diagnostic id (CSWINRT3001) and URL format used to flag the reference-assembly-only WindowsRuntimeObject constructor.

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>

* Add a reference-assembly-only constructor for WindowsRuntimeObject

After #2446 all WindowsRuntimeObject constructors live in the implementation-only WindowsRuntimeObject.Impl.cs and are stripped from the reference assembly, so the compiler would synthesize a protected parameterless constructor. That constructor is absent from the implementation assembly and would throw MissingMethodException at runtime if a user type derived from WindowsRuntimeObject.

Explicitly define it for the reference assembly only, marked obsolete (CSWINRT3001) and hidden, so deriving from WindowsRuntimeObject produces a build diagnostic instead. Only generated projections may derive from it.

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>

* Add back the CSWINRT3001 diagnostics doc

Re-add the diagnostics doc removed in #2434, updated for the new scenario (deriving from WindowsRuntimeObject is not supported), and rename it to match the diagnostic id (updating the solution reference, which was previously dangling).

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code cleanup Code cleanup and refactoring CsWinRT 3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants