Proper way to put attributes in generated properties when using sour generators #217
-
What is the proper way to preserve attributes of observable properties when using source generators? Example private string? firstName;
[Required]
[CustomValidatorBlaBla]
public string? FirstName
{
get => firstName;
set
{
if (SetProperty(ref firstName, value))
{
OnPropertyChanged(nameof(FullName));
GreetUserCommand.NotifyCanExecuteChanged();
}
}
}
private string? lastName;
public string? LastName
{
get => lastName;
set
{
if (SetProperty(ref lastName, value))
{
OnPropertyChanged(nameof(FullName));
GreetUserCommand.NotifyCanExecuteChanged();
}
}
}
public string? FullName => $"{FirstName} {LastName}"; Whne using generators we code as bellow [ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyCanExecuteFor(nameof(GreetUserCommand))]
private string? firstName;
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyCanExecuteFor(nameof(GreetUserCommand))]
private string? lastName;
public string? FullName => $"{FirstName} {LastName}"; How I make Required and CustomValudatorBlaBla be applied to FirstName property generetaded? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You can just use the attribute, and it'll be automatically ported over to the generated property 🙂 |
Beta Was this translation helpful? Give feedback.
-
I resolve this issue using reflection and reading private fields attributes with same name of propretyes and uncaptalize the first letter of name. |
Beta Was this translation helpful? Give feedback.
-
Tracked by issue #208 |
Beta Was this translation helpful? Give feedback.
Tracked by issue #208