Example #1
0
        public void WriteYaml(IEmitter emitter, object value, Type type)
        {
            var color     = (Color)value;
            var converter = new System.Drawing.ColorConverter();
            var str       = converter.ConvertToInvariantString(color);

            emitter.Emit(new Scalar(str));
        }
Example #2
0
 public void ConvertToInvariantString_Name(string name)
 {
     var conv = new ColorConverter();
     Assert.Equal(name, conv.ConvertToInvariantString(Color.FromName(name)));
 }
Example #3
0
 public void ConvertToInvariantString(int a, int r, int g, int b)
 {
     var conv = new ColorConverter();
     var str = conv.ConvertToInvariantString(Color.FromArgb(a, r, g, b));
     Assert.Equal($"{a}, {r}, {g}, {b}", str);
 }
    ConvertTo
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value,
        Type destinationType
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is ColorColumnAutoFillUserSettings);
        Debug.Assert( destinationType == typeof(String) );
        AssertValid();

        ColorColumnAutoFillUserSettings oColorColumnAutoFillUserSettings =
            (ColorColumnAutoFillUserSettings)value;

        ColorConverter oColorConverter = new ColorConverter();

        // Use a simple tab-delimited format.  Sample string:
        //
        // "false\tfalse\t0\t10\tRed\tGreen\tfalse\tfalse\ttrue"
        //
        // WARNING: If this format is changed, you must also change the
        // DefaultSettingValueAttribute for each property in the
        // AutoFillUserSettings class that is of type
        // ColorColumnAutoFillUserSettings.

        return ( String.Format(CultureInfo.InvariantCulture,

            "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}"
            ,
            oColorColumnAutoFillUserSettings.UseSourceNumber1,
            oColorColumnAutoFillUserSettings.UseSourceNumber2,
            oColorColumnAutoFillUserSettings.SourceNumber1,
            oColorColumnAutoFillUserSettings.SourceNumber2,

            oColorConverter.ConvertToInvariantString(
                oColorColumnAutoFillUserSettings.DestinationColor1),

            oColorConverter.ConvertToInvariantString(
                oColorColumnAutoFillUserSettings.DestinationColor2),

            oColorColumnAutoFillUserSettings.IgnoreOutliers,
            oColorColumnAutoFillUserSettings.UseLogs,
            oColorColumnAutoFillUserSettings.SourceColumnContainsNumbers
            ) );
    }
    ConvertToString()
    {
        AssertValid();

        ColorConverter oColorConverter = new ColorConverter();

        String [] asCategoryNames = (m_oCategoryNames == null) ?
            new String [0] : m_oCategoryNames.ToArray();

        return ( String.Join(PerWorkbookSettings.FieldSeparatorString,

            new String [] {
                base.ConvertToString(),

                ( new System.ComponentModel.BooleanConverter() ).
                    ConvertToInvariantString(m_bSourceColumnContainsNumbers),

                oColorConverter.ConvertToInvariantString(
                    m_oDestinationColor1),

                oColorConverter.ConvertToInvariantString(
                    m_oDestinationColor2),

                String.Join(PerWorkbookSettings.SubFieldSeparatorString,
                    asCategoryNames)
            } ) );
    }
    ConvertTo
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value,
        Type destinationType
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is LabelUserSettings);
        Debug.Assert( destinationType == typeof(String) );
        AssertValid();

        LabelUserSettings oLabelUserSettings = (LabelUserSettings)value;

        // Use a simple tab-delimited format.  Note that newer settings have
        // been added to the end, so related settings are not all contiguous.
        // Sample string:
        //
        // "Microsoft Sans Serif, 8.25pt\tWhite\tBottomCenter\t2147483647\t
        // 4294967295\tBlack\ttrue\t200\tBlack\t86\tMiddleCenter";

        ColorConverter oColorConverter = new ColorConverter();

        return ( String.Format(CultureInfo.InvariantCulture,

            "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}"
            ,
            ( new FontConverter() ).ConvertToInvariantString(
                oLabelUserSettings.Font),

            oColorConverter.ConvertToInvariantString(
                oLabelUserSettings.VertexLabelFillColor),

            oLabelUserSettings.VertexLabelPosition,
            oLabelUserSettings.VertexLabelMaximumLength,
            oLabelUserSettings.EdgeLabelMaximumLength,

            oColorConverter.ConvertToInvariantString(
                oLabelUserSettings.EdgeLabelTextColor),

            oLabelUserSettings.VertexLabelWrapText,
            oLabelUserSettings.VertexLabelWrapMaxTextWidth,

            oColorConverter.ConvertToInvariantString(
                oLabelUserSettings.GroupLabelTextColor),

            oLabelUserSettings.GroupLabelTextAlpha,
            oLabelUserSettings.GroupLabelPosition
            ) );
    }
Example #7
0
        /// <summary>
        /// Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
        void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
        {
            ColorConverter conv = new ColorConverter();

            writer.WriteElementString("TextColor", conv.ConvertToInvariantString(TextColor));
            writer.WriteElementString("BackColor", conv.ConvertToInvariantString(BackColor));
            writer.WriteElementString("DisplayMode", DisplayMode.ToString("G"));
            writer.WriteElementString("BlinkTimeSeparator", BlinkTimeSeparator.ToString());
            writer.WriteElementString("UseUpperCase", UseUpperCase.ToString());
        }