jCalc/Calculator.xaml.cs
/// <summary>
/// Allows use of Description attribute in Enum for printing
/// </summary>
/// <param name="value">Enum constant</param>
/// <returns>Display value of enum</returns>
Allows use of Description attribute in Enum for printing
Allows use of Description attribute in Enum for printing
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;
        }
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 ; }
Allows use of Description attribute in Enum for printing
Allows use of Description attribute in Enum for printing
Display value of enum
Display value of enum
Enum
this
value
None