CommunityToolkit / CommunityToolkit/dotnet

Optionally generate partial method or call method optionally when using ObservablePropertyAttribute

Open
#1,178 0 comments 0 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Overview

It's not possible to generate a virtual OnPropertyChanged method right now.
On changing/changed method of property generated as partial.
I want to override changing/changed method by subclass.

### API breakdown

None.

### Usage example

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

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

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

### Breaking change?

No

### Alternatives

```csharp
[ObservableProperty]
private partial string _field;

partial void OnFieldChanged(string value)
{
OnFieldChanged2(value);
}

protected virtual void OnFieldChanged2(string value) { }
```

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.