Skip to content

Add [Experimental] To [BindableProperty]#2990

Merged
TheCodeTraveler merged 9 commits intomainfrom
Add-`RequiresPreviewFeaturesAttribute`
Dec 8, 2025
Merged

Add [Experimental] To [BindableProperty]#2990
TheCodeTraveler merged 9 commits intomainfrom
Add-`RequiresPreviewFeaturesAttribute`

Conversation

@TheCodeTraveler
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler commented Dec 5, 2025

Description of Change

This PR adds the [Experimental] To [BindableProperty].

As discussed in our December 2025 Standup, our plan is to release [BindableProperty] in the CommunityToolkit.Maui NuGet Package as an experimental feature that developers are required to opt-in to until we are confident it is ready to be promoted to stable.

As Microsoft notes in its documentation, this attribute allows us to ship preview features in a stable library:

ExperimentalAttribute allows call sites to be flagged with a diagnostic that indicates that an experimental feature is used. You can use this attribute to ship preview features in otherwise stable libraries.

With the new [Experimental] attribute, the this is now the generated code for BindablePropertyAttribute:

// <auto-generated>
// See: CommunityToolkit.Maui.SourceGenerators.Internal.BindablePropertyAttributeSourceGenerator

#pragma warning disable
#nullable enable
namespace CommunityToolkit.Maui;

[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.Experimental("MCTEXP001")]
sealed partial class BindablePropertyAttribute : global::System.Attribute
{
	public string? PropertyName { get; }
	public global::System.Type? DeclaringType { get; set; }
	public object? DefaultValue { get; set; }
	public global::Microsoft.Maui.Controls.BindingMode DefaultBindingMode { get; set; }
	public string ValidateValueMethodName { get; set; } = string.Empty;
	public string PropertyChangedMethodName { get; set; } = string.Empty;
	public string PropertyChangingMethodName { get; set; } = string.Empty;
	public string CoerceValueMethodName { get; set; } = string.Empty;
	public string DefaultValueCreatorMethodName { get; set; } = string.Empty;
}

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

Once we confirm that [BindableProperty] is stable we will remove [Experimental] promoting it to stable.

This PR also adds <NoWarn>MCTEXP001</NoWarn> to Directory.Build.props which enables our libraries to opt-in to the experimental [BindableProperty]. Without this NoWarn, the [Experimental] would generate a compiler error.

This PR also removes <InternalsVisibleTo Include="CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests"/> from Directory.Build.props because it was causing a compiler error due to the fact that PolySharp provides an implementation of System.Diagnostics.CodeAnalysis.ExperimentalAttribute (so that we can use in .NET Standard 2.0 library) which was conflicting a conflicting-types error with the actual .NET 10 implementation of System.Diagnostics.CodeAnalysis.ExperimentalAttribute provided by the BCL in CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests.

@TheCodeTraveler TheCodeTraveler marked this pull request as draft December 5, 2025 19:12
@TheCodeTraveler TheCodeTraveler marked this pull request as ready for review December 5, 2025 19:18
@TheCodeTraveler TheCodeTraveler merged commit c434100 into main Dec 8, 2025
10 checks passed
@TheCodeTraveler TheCodeTraveler deleted the Add-`RequiresPreviewFeaturesAttribute` branch December 8, 2025 18:46
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant