-
Notifications
You must be signed in to change notification settings - Fork 11
Display properties names
Vsevolod Pilipenko edited this page Jul 19, 2022
·
2 revisions
Some validators uses string.Format
and paste a name of property in a message. For example: {PropertyName} should not be empty
You can set name of property using ReactiveValidation.Attributes.DisplayNameAttribute
:
[DisplayName(DisplayName = "Phone number")]
public string? PhoneNumber { get; set; }
You can create localized names of properties use [DisplayName(DisplayNameKey = "key")]
and [DisplayName(DisplayNameResource = "resource", DisplayNameKey = "key")]
. More about this you can read here.
If you use your own attributes or want to have opportunity to get name from another source, you should implement ReactiveValidation.IDisplayNameResolver
and setup it:
ValidationOptions
.Setup()
.UseCustomDisplayNameResolver(new YourDisplayNameResolver);
You can use as sample DefaultDisplayNameResolver.