Skip to content

Use a dedicated attribute to mark implementation-only members#2434

Open
Sergio0694 wants to merge 6 commits into
staging/winrt-runtime-ref-assemblyfrom
user/sergiopedri/implementation-only-attribute
Open

Use a dedicated attribute to mark implementation-only members#2434
Sergio0694 wants to merge 6 commits into
staging/winrt-runtime-ref-assemblyfrom
user/sergiopedri/implementation-only-attribute

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Replace the [Obsolete] + [EditorBrowsable(EditorBrowsableState.Never)] pattern previously used to mark implementation-only members in WinRT.Runtime with a new, dedicated [WindowsRuntimeImplementationOnlyMember] attribute.

Motivation

Implementation-only members (constructors, methods, properties, and helper types consumed only by generated projections and interop code) were previously marked with a verbose [Obsolete(..., DiagnosticId = "CSWINRT3001", ...)] attribute combined with [EditorBrowsable(EditorBrowsableState.Never)]. This relied on an obsolete-diagnostic message to discourage usage and required suppressing CSWINRT3001 across the whole project.

This PR introduces a single, purpose-built marker attribute that makes the intent explicit. Crucially, the attribute is [Conditional("WINDOWS_RUNTIME_REFERENCE_ASSEMBLY")], so it is only emitted when building reference assemblies (where these members would not be present anyway) and is fully stripped from the shipping WinRT.Runtime.dll.

This is the first PR in a series: a follow-up will use this marker to completely strip implementation-only members from the reference .dll, so consumers compiling against the reference assembly will not see them at all.

Changes

  • src/WinRT.Runtime2/Attributes/WindowsRuntimeImplementationOnlyMemberAttribute.cs: new internal sealed, non-inherited marker attribute targeting all members, conditional on WINDOWS_RUNTIME_REFERENCE_ASSEMBLY.
  • src/WinRT.Runtime2/ (200+ files): replace the [Obsolete(...)] + [EditorBrowsable(...)] pattern with [WindowsRuntimeImplementationOnlyMember] across ABI types, interop services, marshallers, native object wrappers, vtables, and projection impls; remove the now-unused using System.ComponentModel; imports.
  • src/WinRT.Runtime2/Properties/WindowsRuntimeConstants.cs: deleted; it held the CSWINRT3001 obsolete message, diagnostic id, and diagnostics URL format that are no longer needed.
  • src/WinRT.Runtime2/WinRT.Runtime.csproj: remove the CSWINRT3001 NoWarn suppression.
  • docs/diagnostics/cswinrt30001.md: deleted; the CSWINRT3001 diagnostic no longer applies.
  • src/WinRT.Runtime2/InteropServices/ProjectionImpls/IActivationFactoryImpl.cs: convert the last occurrence that was missed in the bulk change (it still referenced the deleted WindowsRuntimeConstants, which would otherwise break the build).

Sergio0694 and others added 6 commits June 11, 2026 16:20
Introduce an internal sealed attribute to mark implementation-only members for WinRT runtime. The attribute targets all members, is non-inherited, and is conditional on WINDOWS_RUNTIME_REFERENCE_ASSEMBLY so it is emitted only in reference assemblies; this makes it explicit which members are implementation-only and allows them to be stripped from the runtime DLL. Added at src/WinRT.Runtime2/Attributes/WindowsRuntimeImplementationOnlyMemberAttribute.cs.
…members

Replace the combination of [EditorBrowsable(Never)] and [Obsolete(...)] with the single [WindowsRuntimeImplementationOnlyMember] attribute on implementation-only members across WinRT.Runtime.

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
Delete WindowsRuntimeConstants.cs which contained constants for WinRT private implementation detail messaging, the PrivateImplementationDetailObsoleteDiagnosticId (CSWINRT3001), and the CsWinRT diagnostics URL format. These constants have been removed from the project.
Delete the NoWarn entry and its comment for CSWINRT3001 from src/WinRT.Runtime2/WinRT.Runtime.csproj so warnings about '[Obsolete]' private implementation details are no longer suppressed. This change surfaces those warnings for visibility during builds.
This diagnostic is no longer applicable now that the private
implementation detail [Obsolete] attributes have been removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file was missed in the bulk conversion to the new attribute; it still referenced the now-deleted WindowsRuntimeConstants type, which would break the build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sergio0694 Sergio0694 added code cleanup Code cleanup and refactoring CsWinRT 3.0 labels Jun 11, 2026
@Sergio0694 Sergio0694 requested a review from manodasanW June 11, 2026 23:37
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.

1 participant