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

Abierto
#1,038 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
tooling

Línea de trabajo

Comienza localizando el generador de código fuente ObservableProperty y la lógica de propagación de atributos que utiliza para los atributos de propiedades. Después, reproduce el ejemplo de C# proporcionado con CommunityToolkit.Mvvm 8.3.2 y verifica que el PropertyListIncludeAttribute generado conserve el argumento con nombre category.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C#
Estrellas
3.8k
Forks
402
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CommunityToolkit/dotnet

Todos los issues de CommunityToolkit/dotnet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.