I'm using asp.net MVC 5 with EntityFramework 6 DataAnnotations.
I would like to know if there is a way to get all DisplayName
of an object and save them in a variable into a Controller class.
For example, considering the class:
public class Class1
{
[DisplayName("The ID number")]
public int Id { get; set; }
[DisplayName("My Value")]
public int Value { get; set; }
[DisplayName("Label name to display")]
public string Label { get; set; }
}
How to get the values of DisplayName
for all attributes? For example how to create a function that returns a Dictionary< string,string >
which has a key with attribute name and value with DisplayName
, like this:
{ "Id": "The ID name", "Value": "My Value", "Label": "Label name to display"}.
I have seen this topic stackoverflow - get the value of DisplayName attribute but I have no ideas of a way to extends this code.