Skip to content

Generate partial method or call method optionally.#1179

Open
Kation wants to merge 1 commit intoCommunityToolkit:mainfrom
Kation:optional_generate
Open

Generate partial method or call method optionally.#1179
Kation wants to merge 1 commit intoCommunityToolkit:mainfrom
Kation:optional_generate

Conversation

@Kation
Copy link
Copy Markdown

@Kation Kation commented Apr 3, 2026

Closes #1178
This pull request adds optional for ObservablePropertyAttribute to indicates whether to generate changing/changed method and call changing/changed method.

[ObservableProperty(GenerateOnChanging = false, GenerateOnChanged = false, CallOnChanging = false, CallOnChanged = false)]
private partial string _field;

Indicates not generate changing/changed method still call them when setting property.
Thereforce we can make a protected method.

[ObservableProperty(GenerateOnChanged = false)]
private partial string _field;

protected virtual void OnFieldChanged(string? oldValue, string newValue) { }
protected virtual void OnFieldChanged(string value) { }

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
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • 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

Other information

Documentation have not update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optionally generate partial method or call method optionally when using ObservablePropertyAttribute

1 participant