Dynamic DataAnnotes dynamically set using the t4 template

Is there a way to dynamically set data according to some values ​​in the database?

My requirement is this:

Display(Name="DispName")] public string DName{get;set;} 

Instead of hardcoding Name = "DispName" to display the DataAnnotation, I want to get some value from the database and put the int attribute Name. as:

 [Display(Name=SomeValueFromDB)] public string DName{get;set;} 

This should also be done using the t4 template.

Is there any way to do this?

Hello,

Sujit

+6
source share
1 answer

Not sure I understand what you mean. For me, the T4 generation doesn't make much sense in your case, but look at the Phil Haack approach: http://haacked.com/archive/2011/07/14/model-metadata-and-validation-localization-using-conventions.aspx

Unlike your query, it modifies data annotations at runtime using its own ModelMetadataProvider.

+3
source

Source: https://habr.com/ru/post/945155/


All Articles