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.03k stars 297 forks source link

[ObservableRecipient] Broadcast(...); is not being generated, when the [Display] attribute is being added last #242

Closed Insire closed 2 years ago

Insire commented 2 years ago

Describe the bug

    /// <summary>
    /// Broadcast(__oldValue, value, "SomeProperty"); is not being generated, when the [Display] attribute is being added last
    /// </summary>
    [ObservableRecipient]
    public sealed partial class AlsoBroadcastChangeNotGenerated : ObservableValidator
    {
        [ObservableProperty]
        [AlsoBroadcastChange]
        [Display(Name = "Is static")]
        private object? _someProperty;
    }

Regression

No response

Steps to reproduce

Microsoft Visual Studio Community 2022
Version 17.1.6
VisualStudio.17.Release/17.1.6+32421.90
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022   00482-90000-00000-AA013
Microsoft Visual C++ 2022

.NET Core Debugging with WSL   1.0
.NET Core Debugging with WSL

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   17.1.363.30963
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   17.1.363.30963
For additional information, visit https://www.asp.net/

AvaloniaPackage Extension   1.0
AvaloniaPackage Visual Studio Extension Detailed Info

Azure App Service Tools v3.0.0   17.1.363.30963
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.1.363.30963
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.1.0-5.22165.10+e555772db77ca828b02b4bd547c318387f11d01f
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Cake for Visual Studio 2022   0.1.1.0
Adds support for the Cake build tool in Visual Studio 2022. Includes support for the Task Runner Explorer, new templates and bootstrapping important Cake files.

CodeMaid   12.0
CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, R, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   17.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.161+abc97ecc7d.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.2
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   17.1.10 (65f98f5)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   6.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.0.0.2206201+62a2c1d6162f828801565a7ca26d9d48b810a05b
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62203.25080
Microsoft SQL Server Data Tools

StylerPackage Extension   1.0
StylerPackage Visual Stuido Extension Detailed Info

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.1229.2001
TypeScript Tools for Microsoft Visual Studio

UnoPlatformPackage Extension   1.0
UnoPlatformPackage Visual Studio Extension Detailed Info

Visual Basic Tools   4.1.0-5.22165.10+e555772db77ca828b02b4bd547c318387f11d01f
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.1.0-beta.21610.4+07b5673e4f2fa7630e78abe37f16b372353a7242
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSColorOutput64   2022.2
Color output for build and debug windows - https://mike-ward.net/vscoloroutput

Xamarin   17.1.0.329 (d17-1@bc74cf0)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.1.0.87 (remotes/origin/main@d50fb5635)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.1.8 (590388a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   12.2.4.3 (d17-1/fc1125e)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: adf1bc4
    Java.Interop: xamarin/java.interop/d17-1@7ac33610
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.37.1@0893b3b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-1@db125a7

Xamarin.iOS and Xamarin.Mac SDK   15.8.0.5 (cc19b50de)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Repro [here](https://github.com/Insire/CommunityToolkit.Mvvm.Bugs/blob/main/WpfApp1/AlsoBroadcastChangeNotGenerated.cs)

Expected behavior

    partial class AlsoBroadcastChangeNotGenerated
    {
        /// <inheritdoc cref="_someProperty"/>
        [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.0.0.0")]
        [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
        public object? SomeProperty
        {
            get => _someProperty;
            set
            {
                if (!global::System.Collections.Generic.EqualityComparer<object?>.Default.Equals(_someProperty, value))
                {
                    object? __oldValue = _someProperty;
                    OnSomePropertyChanging(value);
                    OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.SomeProperty);
                    _someProperty = value;
                    OnSomePropertyChanged(value);
                    OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.SomeProperty);
                    Broadcast(__oldValue, value, "SomeProperty");
                }
            }
        }

this code should be automatically generated

Screenshots

generated code:

grafik

code that should be generated:

grafik

IDE and version

VS 2022

IDE version

No response

Nuget packages

Nuget package version(s)

8.0.0-preview3

Additional context

@Sergio0694 asked me to report this here

Help us help you

No, just wanted to report this

michael-hawker commented 2 years ago

Also note related to #208 - Don't think Display would be forwarded anyway, right @Sergio0694?