Skip to content

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

Overriding name of property

You can set name of property using ReactiveValidation.Attributes.DisplayNameAttribute:

[DisplayName(DisplayName = "Phone number")]
public string? PhoneNumber { get; set; }

Localization

You can create localized names of properties use [DisplayName(DisplayNameKey = "key")] and [DisplayName(DisplayNameResource = "resource", DisplayNameKey = "key")]. More about this you can read here.

Using another source for display property name

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.