Обходной путь для требования константы времени компиляции в ASP.NET Core DataAnnotations ⇐ C#
Обходной путь для требования константы времени компиляции в ASP.NET Core DataAnnotations
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
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
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
[Runtime.interopservices.marshal] :: getactiveObject Обходной путь для .NET Core
Anonymous » » в форуме C# - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-
-
-
[Runtime.interopservices.marshal] :: getactiveObject Обходной путь для .NET Core
Anonymous » » в форуме C# - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-
-
-
[Runtime.interopservices.marshal] :: GetactiveObject Обходной путь для .NET Core [закрыто]
Anonymous » » в форуме C# - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-