CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

`[INotifyPropertyChanged]` is not supported on records #610

Open nxtn-staged opened 1 year ago

nxtn-staged commented 1 year ago

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

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

CodingOctocat commented 1 year ago

Does record represent immutability?

BYJRK commented 1 year ago

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

ememadegbola commented 1 year ago

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