-
Notifications
You must be signed in to change notification settings - Fork 299
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
Allow custom property attributes for [ObservableProperty] #413
Comments
@333fred I know you were doing some work to block uses of invalid attribute targets, was that restricted to not recognized targets (ie. CS0658), or would that include invalid targets (ie. CS0657) too? As in, could we rely on that not being an error? |
Additionally (cc. @chsienki) would there be a way for a generator to suppress CS0657 on that field on behalf of users? As in, a way for it to basically tell Roslyn that yes those are ignored, but the generator actually needs that info, so it shouldn't be a warning. Being able to suppress those CS0657 from the generator would make the UX much better for the end users 🙂 |
@Sergio0694 The generator can't do that, but you can ship a diagnostic suppressor in the same assembly. They were basically invented for this purpose :) https://github.com/dotnet/roslyn/blob/32c1f2d2df534f9ae3679807ecdfdd0706e8da6d/docs/analyzers/DiagnosticSuppressorDesign.md |
Ooh that's awesome, thank you! I'll look into it, this seems very promising then 😄 |
”which Roslyn ignores but doesn't block.“ Does Mean “It's just a makeshift or an expedient” |
Should this be available on RelayCommand? [RelayCommand]
[property: Newtonsoft.Json.JsonIgnore]
private void DoWork() { } When I try to serialize an object which contains this code, |
This is doable, though would need additional justification for the work. Could you open a dedicated proposal? |
While this is not related to the toolkit, I'd like to add that serializing ViewModels is usually a sign of some misstep. Consider serializing the backing model, which is often a trivially serializable DTO or POCO, instead. |
Overview
Right now, it's not possible to specify property attributes when using
[ObservableProperty]
, which has been a pain point for some users, as it forces you to go back to manual properties in that case. There's been several asks for this in the past, see (#228, #217, #208). We could technically support this via the explicitproperty:
target, which Roslyn ignores but doesn't block. That is:The generator would emit:
This would effectively allow users to have perfect control over attributes on target properties.
The text was updated successfully, but these errors were encountered: