namespace InstrumentationControls
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Globalization;

    public class BevelConverter : TypeConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                Bevel bevel = (Bevel) value;
                return (bevel.Style.ToString() + (bevel.OutterBorder ? "+OutterBorder" : "") + (bevel.InnerBorder ? "+InnerBorder" : ""));
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            BevelStyle none = BevelStyle.None;
            bool outterBorder = false;
            bool innerBorder = false;
            if (propertyValues.Contains("Style"))
            {
                none = (BevelStyle) propertyValues["Style"];
            }
            if (propertyValues.Contains("OutterBorder"))
            {
                outterBorder = (bool) propertyValues["OutterBorder"];
            }
            if (propertyValues.Contains("InnerBorder"))
            {
                innerBorder = (bool) propertyValues["InnerBorder"];
            }
            return new Bevel(none, outterBorder, innerBorder);
        }

        public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            return TypeDescriptor.GetProperties(typeof(Bevel), attributes);
        }

        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}
