Guest User

Untitled

a guest
Mar 5th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. public interface IDisplayName { }
  2.  
  3. public class Person : IDisplayName
  4. {
  5.     [DisplayName("Имя")]
  6.     public string Name { get; set; }
  7.  
  8.     [DisplayName("Фамилия")]
  9.     public string LastName { get; set; }
  10.  
  11.     [DisplayName("Возраст")]
  12.     public int Age { get; set; }
  13. }
  14.  
  15. public static class DisplayNameExtensions
  16. {
  17.     public static string GetDisplayName<T>(this T _, Expression<Func<T, object>> propertyExpression)
  18.         where T : IDisplayName
  19.     {
  20.         ...
  21.     }
  22. }
  23.  
  24. var person = new Person { Name = "Name", LastName = "LastName", Age = 1 };
  25. var ageTitle = person.GetDisplayName(x => x.Age);
Advertisement
Add Comment
Please, Sign In to add comment