Ejemplo 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);
        }
Ejemplo 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);
        }