Ejemplo n.º 1
0
        /// <summary>
        /// Convierte el enumerado a su nombre asociado en [Description]
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ToName(this System.Enum value)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            var attribute = value.GetAttribute <DescriptionAttribute>();

            return(attribute?.Description ?? value.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the registry key for an enumeration member, or null if it is not set.
 /// </summary>
 /// <param name="enum">The enumeration member.</param>
 /// <returns>The registry key attribute for the member, or null if it is not set.</returns>
 public static string GetRegistryKey(Enum @enum)
 {
     var registryKeyAttribute = @enum.GetAttribute<RegistryKeyAttribute>();
     return registryKeyAttribute != null ? registryKeyAttribute.RegistryKey : null;
 }
Ejemplo n.º 3
0
        // This method creates a specific call to the above method, requesting the
        // Description MetaData attribute.
        /// <summary>
        /// Converts to description.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static string ToDescription(this System.Enum value)
        {
            DescriptionAttribute attribute = value.GetAttribute <DescriptionAttribute>();

            return(attribute == null?value.ToString() : attribute.Description);
        }
 public static string GetDescription(this Enum enumvValue)
 {
     return(enumvValue?.GetAttribute <DescriptionAttribute>()?.Description ?? enumvValue?.ToString() ?? string.Empty);
 }
Ejemplo n.º 5
0
 public static String GetCode(Enum value)
 {
     return value.GetAttribute<CodeAttribute>().Value;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Get description attribute of enum
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string GetDescription(this System.Enum value)
 {
     return(value.GetAttribute <DescriptionAttribute>().Description);
 }