| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace CD67.FicheCollege.Entity
- {
- public static class Constants
- {
- public enum Statut
- {
- [Display(Description = "A saisir")]
- A_SAISIR,
- [Display(Description = "En cours de saisie")]
- EN_COURS_DE_SAISIE,
- [Display(Description = "Proposé")]
- PROPOSE,
- [Display(Description = "Validé")]
- VALIDE
- }
- /// <summary>
- /// Fonction permettant de récupérer la valeur notée en description d'une énumération
- /// </summary>
- /// <param name="value">Elément d'une énumération</param>
- /// <returns>Description associée à l'élément</returns>
- public static string GetDescription(this Enum value)
- {
- Type type = value.GetType();
- string name = Enum.GetName(type, value);
- if (name != null)
- {
- FieldInfo field = type.GetField(name);
- if (field != null)
- {
- DescriptionAttribute attr =
- Attribute.GetCustomAttribute(field,
- typeof(DescriptionAttribute)) as DescriptionAttribute;
- if (attr != null)
- {
- return attr.Description;
- }
- }
- }
- return null;
- }
- }
- }
|