dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

`[INotifyPropertyChanged]` is not supported on records

Open nxtn-staged opened this issue 2 years ago • 3 comments

Describe the bug

When applied to record (class) types, the [INotifyPropertyChanged] attribute has no effect.

Regression

No response

Steps to reproduce

[INotifyPropertyChanged]
partial record Record()
{
    [ObservableProperty]
    private int x;
}

Expected behavior

The PropertyChanged event and the OnPropertyChanged method are generated.

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

No response

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

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

nxtn-staged avatar Feb 16 '23 12:02 nxtn-staged

Does record represent immutability?

CodingOctocat avatar Jun 20 '23 13:06 CodingOctocat

Does record represent immutability?

Record type is not necessarily asking all members to be immutable. It can still provide useful functions such as a nice ToString format and equal checking

BYJRK avatar Jun 24 '23 04:06 BYJRK

I've run into this issue too when trying to work with record types. The workaround we've used is to create a new ObservableRecord type using the source from ObservableObject with one or two tweaks. Would be nice to have "official" support for records though

ememadegbola avatar Jul 15 '23 14:07 ememadegbola