dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

ObservableProperty attribute doesn't generate proper code for TaskNotifier type

Open hawkerm opened this issue 3 years ago • 0 comments

Describe the bug

When trying to observe a Task using the MVVM Toolkit, there's a special helper type called TaskNotifier, as called out in the docs here.

However, this currently doesn't generate the proper output when using the source generator helper:

        public global::CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier<bool>? InitializeTask
        {
            get => _initializeTask;
            set
            {
                if (!global::System.Collections.Generic.EqualityComparer<global::CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier<bool>?>.Default.Equals(_initializeTask, value))
                {
                    OnInitializeTaskChanging(value);
                    OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.InitializeTask);
                    _initializeTask = value;
                    OnInitializeTaskChanged(value);
                    OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.InitializeTask);
                }
            }
        }

Note how the value is set directly and no monitor is setup as is normally done in the ]SetPropertyAndNotifyOnCompletion method](https://github.com/CommunityToolkit/dotnet/blob/9d1a525d04299e5421cb3e5917825fee2bc11a18/CommunityToolkit.Mvvm/ComponentModel/ObservableObject.cs#L485).

Also note how the property is using TaskNotifier as the type instead of Task.

Regression

No response

Steps to reproduce

1. Create an Observable object
2. Add a task field with a SG attribute:


[ObservableProperty]
private TaskNotifier<bool>? _initializeTask;

Expected behavior

Generated property should be of type Task.

Generated method should call or be the same code as SetPropertyAndNotifyOnCompletion.

Have an additional partial method that represents the callback for task completion OnInitiaizeTaskCompleted?

hawkerm avatar Sep 04 '22 08:09 hawkerm