ObservableProperty source generator messes up named arguments for attributes assigned with property:attribute

Aperta
#1,038 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
tooling

Direzione di ricerca

Inizia individuando il generatore di codice sorgente ObservableProperty e la logica di inoltro degli attributi che utilizza per gli attributi delle proprietà. Riproduci quindi l'esempio C# fornito con CommunityToolkit.Mvvm 8.3.2 e verifica che il PropertyListIncludeAttribute generato conservi l'argomento denominato category.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

analyzer :eyeglasses: mvvm-toolkit :toolbox:
Describe the bug

When adding a custom attribute using [property:MyAttribute] the ObservableProperty source generator does not generate named arguments passed to the attributes constructor.

Regression

No response

Steps to reproduce
  1. Custom attribute with optional constructor arguments
public sealed class PropertyListIncludeAttribute : Attribute
{
    public string? Category { get; private init; }
    public string? Label { get; private init; }

    public PropertyListIncludeAttribute(string? label = null, string? category = null)
    {
        Label = label;
        Category = category;
    }
}
  1. Usage with ObservableProperty
[ObservableProperty]
[property: PropertyListInclude(category: "Another Category")]
private int testInt;
  1. See problem in source generated result
/// <inheritdoc cref="testInt"/>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.3.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::DotNetElements.DevTools.SDK.Core.PropertyListIncludeAttribute("Another Category")]
public int TestInt
{
    get => testInt;
    set
    {
        if (!global::System.Collections.Generic.EqualityComparer<int>.Default.Equals(testInt, value))
        {
            OnTestIntChanging(value);
            OnTestIntChanging(default, value);
            OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.TestInt);
            testInt = value;
            OnTestIntChanged(value);
            OnTestIntChanged(default, value);
            OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.TestInt);
        }
    }
}
Expected behavior

Named arguments need to be properly passed to the source generator

[global::DotNetElements.DevTools.SDK.Core.PropertyListIncludeAttribute(category:"Another Category")]
Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages
  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)

8.3.2

Additional context

No response

Help us help you

No, just wanted to report this

Lingua principale
C#
Stelle
3.8k
Fork
402
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CommunityToolkit/dotnet

Tutte le issue di CommunityToolkit/dotnet

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.