Обходной путь для требования константы времени компиляции в ASP.NET Core DataAnnotationsC#

Место общения программистов C#
Ответить
Anonymous
 Обходной путь для требования константы времени компиляции в ASP.NET Core DataAnnotations

Сообщение Anonymous »


I have various config values defined in the database or appsettings. But those cannot be used in DataAnnotation attributes (which require compile-time constants), so everything is duplicated in a Constants class too.

For example:

[StringLength(Constants.NAME_MAX_LENGTH, ErrorMessage = "...")] public string Name { get; set; } One can use localisation to get the error message at runtime (from appsettings, database, etc.) and thus skirt the compile-time constant limitation, but as far as I can tell one cannot use the same approach for the min/max properties too (is that correct?)

Is there some roundabout way I can do something similar for the MinimumLength and MaximumLength properties, so that they can be read dynamically at runtime?


Источник: https://stackoverflow.com/questions/781 ... nnotations
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»