Esempio n. 1
0
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((value != null && value.GetType().IsEnum))
            {
                ChoEnumFormatSpec EnumFormat = parameter.GetValueFor("EnumFormat", 0, ChoTypeConverterFormatSpec.Instance.EnumFormat);
                switch (EnumFormat)
                {
                case ChoEnumFormatSpec.Name:
                    return(value.ToString());

                case ChoEnumFormatSpec.Description:
                    return(ChoEnum.ToDescription((Enum)value));

                default:
                    string ft = parameter.GetValueFor <string>("Format", 1);
                    if (ft.IsNullOrWhiteSpace())
                    {
                        return((int)value);    // ((Enum)value).ToString("D");
                    }
                    else
                    {
                        return(((Enum)value).ToString(ft));
                    }
                }
            }

            return(value);
        }
Esempio n. 2
0
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((value != null && value.GetType().IsEnum) && targetType == typeof(string))
            {
                ChoEnumFormatSpec EnumFormat = parameter.GetValueAt(0, ChoTypeConverterFormatSpec.Instance.EnumFormat);
                switch (EnumFormat)
                {
                case ChoEnumFormatSpec.Name:
                    return(value.ToString());

                case ChoEnumFormatSpec.Description:
                    return(ChoEnum.ToDescription((Enum)value));

                default:
                    return(((Enum)value).ToString("D"));
                }
            }

            return(value);
        }
Esempio n. 3
0
 /// <summary>
 /// Checks if an enumerated type is missing a value
 /// </summary>
 public static bool Missing <T>(this Enum obj, T value)
 {
     return(!ChoEnum.Has <T>(obj, value));
 }