ComponentFactory.Krypton.Toolkit.PaletteDrawBordersConverter.ConvertTo C# (CSharp) Method

ConvertTo() public method

Converts the given value object to the specified type, using the specified context and culture information.
public ConvertTo ( ITypeDescriptorContext context, System culture, object value, Type destinationType ) : object
context ITypeDescriptorContext An ITypeDescriptorContext that provides a format context.
culture System A CultureInfo object. If a null reference the current culture is assumed.
value object The Object to convert.
destinationType System.Type The Type to convert the value parameter to.
return object
        public override object ConvertTo(ITypeDescriptorContext context,
                                         System.Globalization.CultureInfo culture,
                                         object value,
                                         Type destinationType)
        {
            // We are only interested in adding functionality for converting to strings
            if (destinationType == typeof(string))
            {
                // Convert object to expected style
                PaletteDrawBorders borders = (PaletteDrawBorders)value;

                // If the inherit flag is set that that is the only flag of interest
                if ((borders & PaletteDrawBorders.Inherit) == PaletteDrawBorders.Inherit)
                    return "Inherit";
                else
                {
                    // Append the names of each border we want
                    StringBuilder sb = new StringBuilder();

                    if ((borders & PaletteDrawBorders.Top) == PaletteDrawBorders.Top)
                        sb.Append("Top");

                    if ((borders & PaletteDrawBorders.Bottom) == PaletteDrawBorders.Bottom)
                    {
                        if (sb.Length > 0)
                            sb.Append(",");

                        sb.Append("Bottom");
                    }

                    if ((borders & PaletteDrawBorders.Left) == PaletteDrawBorders.Left)
                    {
                        if (sb.Length > 0)
                            sb.Append(",");

                        sb.Append("Left");
                    }

                    if ((borders & PaletteDrawBorders.Right) == PaletteDrawBorders.Right)
                    {
                        if (sb.Length > 0)
                            sb.Append(",");

                        sb.Append("Right");
                    }

                    // If no border is wanted then return a fixed string
                    if (sb.Length == 0)
                        sb.Append("None");

                    return sb.ToString();
                }
            }

            // Let base class perform default conversion
            return base.ConvertTo(context, culture, value, destinationType);
        }