Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Lwc-LiuWenCheng opened this issue Feb 5, 2024 · 3 comments
Labels
feature request 📬 A request for new changes to improve functionality

Comments

@Lwc-LiuWenCheng
Copy link

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 Lwc-LiuWenCheng added the feature request 📬 A request for new changes to improve functionality label Feb 5, 2024
@ghost
Copy link

ghost commented Feb 5, 2024

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!

@Arlodotexe Arlodotexe transferred this issue from CommunityToolkit/WindowsCommunityToolkit Mar 12, 2024
@jonmotos
Copy link

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

Inspecting the generated code, the property inherits the attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 📬 A request for new changes to improve functionality
Projects
None yet
Development

No branches or pull requests

3 participants