dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Add Custom Attribute Support for Properties Auto-Generated by [ObservableProperty]

Open Lwc-LiuWenCheng opened this issue 1 year ago • 3 comments

Describe the problem

I propose adding support for custom attributes on properties auto-generated by the [ObservableProperty] in the .NET Community Toolkit. Currently, properties auto-generated using [ObservableProperty] do not support attaching additional attributes directly, limiting their application in scenarios like data validation or UI mapping.

Describe the solution

When using [ObservableProperty], there should be a way to attach additional attributes to the generated properties, rather than manually writing out the full properties. In many cases, we need to attach specific attributes to properties of a data model for data validation, serialization control, or specific UI behaviors. For instance, we might want to use [DataAnnotations] attributes for validating data models, or custom attributes to control how columns are displayed.

Alternatives

No response

Additional info

No response

Help us help you

None

Lwc-LiuWenCheng avatar Feb 05 '24 07:02 Lwc-LiuWenCheng

Hello, 'Lwc-LiuWenCheng! Thanks for submitting a new feature request. I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future!

ghost avatar Feb 05 '24 07:02 ghost

In my experience, doing the following has worked: [property:Required]

Inspecting the generated code, the property inherits the attribute.

jonmotos avatar Mar 13 '24 16:03 jonmotos

You can do that here:

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/observableproperty#adding-custom-attributes

rrickgauer avatar Apr 24 '24 15:04 rrickgauer

Closing this, as it's already supported 🙂

Sergio0694 avatar Aug 20 '24 04:08 Sergio0694