Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for partial properties for [ObservableProperty] #966

Merged
merged 43 commits into from
Oct 27, 2024

Conversation

Sergio0694
Copy link
Member

Closes #555

This PR updates the [ObservableProperty] generator to support partial properties as well.
It includes the following changes:

  • Update the target of all attribute types to support properties too
  • Update generator to handle partial properties
  • Update all diagnostic messages to also mention partial properties
  • Add a new analyzer to error if C# is not set to preview
  • Add a new analyzer to error if using a version of Roslyn that's too old
  • Add a new analyzer to error if a partial property declaration is invalid
  • Add a new analyzer to suggest converting to a partial property when possible
  • Add a new code fixer to automatically update all fields to partial properties
  • Add unit tests for all new features

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tested code with current supported SDKs
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

@Sergio0694 Sergio0694 added feature 💡 A new feature being implemented mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit analyzer 👓 A new analyzer being implemented or updated labels Oct 25, 2024
@Sergio0694 Sergio0694 merged commit 48ed1b4 into main Oct 27, 2024
4 checks passed
@Sergio0694 Sergio0694 deleted the dev/partial-properties branch October 27, 2024 21:50
@@ -20,38 +20,54 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
/// partial class MyViewModel : ObservableObject
/// {
/// [ObservableProperty]
/// private string name;
/// public partial string name { get; set; }

Choose a reason for hiding this comment

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

Just a question: should "name" here also have a capital, since it's now a property? and the generated code below also seems to have a capital?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 👓 A new analyzer being implemented or updated feature 💡 A new feature being implemented mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for [ObservableProperty] on partial properties
3 participants