Skip to content

More convenient usage of the generator #1

@Rekkonnect

Description

@Rekkonnect

The current approach is to declare a field that is basically useless for StyledProperty. What I would prefer is having an attribute that is placed on the containing class, which declares the type and the name of the property and the StyledProperty field.

For example,

[AvaStyledProperty<double>(nameof(MinValue))]
[AvaStyledProperty<double>(nameof(MaxValue))]
[AvaStyledProperty<double>(nameof(CurrentValue))]
public partial class ExampleControl : UserControl
{
}

Generating:

partial class ExampleControl
{
    public static readonly StyledProperty<double> MinValueProperty =
        AvaloniaProperty.Register<ExampleControl, double>(nameof(MinValue));

    public double MinValue
    {
        get => GetValue(MinValueProperty);
        set
        {
            SetValue(MinValueProperty, value);
        }
    }

    public static readonly StyledProperty<double> MaxValueProperty =
        AvaloniaProperty.Register<ExampleControl, double>(nameof(MaxValue));

    public double MaxValue
    {
        get => GetValue(MaxValueProperty);
        set
        {
            SetValue(MaxValueProperty, value);
        }
    }

    public static readonly StyledProperty<double> CurrentValueProperty =
        AvaloniaProperty.Register<ExampleControl, double>(nameof(CurrentValue));

    public double CurrentValue
    {
        get => GetValue(CurrentValueProperty);
        set
        {
            SetValue(CurrentValueProperty, value);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions