Constants.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace CD67.FicheCollege.Entity
  10. {
  11. public static class Constants
  12. {
  13. public enum Statut
  14. {
  15. [Display(Description = "A saisir")]
  16. A_SAISIR,
  17. [Display(Description = "En cours de saisie")]
  18. EN_COURS_DE_SAISIE,
  19. [Display(Description = "Proposé")]
  20. PROPOSE,
  21. [Display(Description = "Validé")]
  22. VALIDE
  23. }
  24. /// <summary>
  25. /// Fonction permettant de récupérer la valeur notée en description d'une énumération
  26. /// </summary>
  27. /// <param name="value">Elément d'une énumération</param>
  28. /// <returns>Description associée à l'élément</returns>
  29. public static string GetDescription(this Enum value)
  30. {
  31. Type type = value.GetType();
  32. string name = Enum.GetName(type, value);
  33. if (name != null)
  34. {
  35. FieldInfo field = type.GetField(name);
  36. if (field != null)
  37. {
  38. DescriptionAttribute attr =
  39. Attribute.GetCustomAttribute(field,
  40. typeof(DescriptionAttribute)) as DescriptionAttribute;
  41. if (attr != null)
  42. {
  43. return attr.Description;
  44. }
  45. }
  46. }
  47. return null;
  48. }
  49. }
  50. }