using System.ComponentModel.DataAnnotations;
public static void Main()
var result = GetTranslatedDisplayName<Test>("Name");
Console.WriteLine(result);
public static string GetTranslatedDisplayName<TModel>(string propertyName)
var modelType = typeof(TModel);
var property = modelType.GetProperty(propertyName);
var display = property.GetCustomAttributes(typeof(DisplayAttribute), true).FirstOrDefault() as DisplayAttribute;
return "OK: " + display.Name;
return "Error: no [Display] attribute set on '{fieldName}'.";
public string Name {get; set; }
public long Id {get; set; }