Skip to content

Update [BindableProperty] Support for Additional Scenarios, Add CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests, Implement [BindableProperty] for Behaviors#2932

Merged
TheCodeTraveler merged 76 commits intomainfrom
Use-`-BindableProperty]`-for-Behaviors
Nov 22, 2025
Merged

Update [BindableProperty] Support for Additional Scenarios, Add CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests, Implement [BindableProperty] for Behaviors#2932
TheCodeTraveler merged 76 commits intomainfrom
Use-`-BindableProperty]`-for-Behaviors

Conversation

@TheCodeTraveler
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler commented Nov 7, 2025

Description of Change

As Discussed in our November 2025 Standup, this PR implements the [BindableProperty] attribute, replacing the manually created BindableProperties.

This PR also adds support to [BindableProperty] for the following scenarios:

  • Property names using a reserved keyword, e.g. @class
  • Properties inside Generic Classes
  • Properties inside Nested Classes
  • Properties using Nullable reference types
  • Properties using Nullable<T>
  • Properties using Array types
  • Properties inside classes using the global namespace
  • Properties inside an inherited class that also has a property using [BindableProperty]
  • Multiple Classes in the same file using [BindableProperty]
  • All default value types, e.g. bool, char, string and enum

This PR also implements CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests.

PR Checklist

Additional information

I've added the breaking change label because the generated code from [BindableProperty] fixes a few typos in BindableProperty names.

@TheCodeTraveler TheCodeTraveler added pending documentation This feature requires documentation breaking change This label is used for PRs that include a breaking change labels Nov 7, 2025
@TheCodeTraveler TheCodeTraveler marked this pull request as ready for review November 21, 2025 20:39
@TheCodeTraveler TheCodeTraveler marked this pull request as draft November 21, 2025 20:46
@TheCodeTraveler TheCodeTraveler marked this pull request as ready for review November 21, 2025 20:47
@TheCodeTraveler
Copy link
Collaborator Author

TheCodeTraveler commented Nov 21, 2025

It looks very well done. Lets spin up CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests as you suggested and test all the scenarios for Create() and DefaultValue

Thanks @ne0rrmatrix! I've added CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests.

It was a ton of hard work, but I was able to catch a few bugs in the source generator, particularly around edge cases. Thanks to these Unit Tests, the [BindableProperty] now supports all of the following scenarios:

  • Property names using a reserved keyword, e.g. @class
  • Properties inside Generic Classes
  • Properties inside Nested Classes
  • Properties using Nullable reference types
  • Properties using Nullable<T>
  • Properties using Array types
  • Properties inside classes using the global namespace
  • Properties inside an inherited class that also has a property using [BindableProperty]
  • Multiple Classes in the same file using [BindableProperty]
  • All default value types, e.g. bool, char, string and enum

@TheCodeTraveler TheCodeTraveler changed the title Implement [BindableProperty] for Behaviors Update [BindableProperty] Support for Additional Scenarios, Add CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests, Implement [BindableProperty] for Behaviors Nov 21, 2025
@TheCodeTraveler TheCodeTraveler removed the pending documentation This feature requires documentation label Nov 21, 2025
ne0rrmatrix
ne0rrmatrix previously approved these changes Nov 21, 2025
Copy link
Member

@ne0rrmatrix ne0rrmatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like you have thought about just about everything I could want or hope for with this. It is amazing! Approved!

@TheCodeTraveler TheCodeTraveler merged commit a77c100 into main Nov 22, 2025
11 checks passed
@TheCodeTraveler TheCodeTraveler deleted the Use-`-BindableProperty]`-for-Behaviors branch November 22, 2025 20:06
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

breaking change This label is used for PRs that include a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants