DumpColor Reference

DumpColor is a utility class for representing colors in Dumpify configuration.

Overview

namespace Dumpify;

public class DumpColor
{
    // Constructors
    public DumpColor(string hexColor);
    public DumpColor(Color color);
    
    // Factory method
    public static DumpColor FromHexString(string hexColor);
    
    // Implicit conversions
    public static implicit operator DumpColor(string hexColor);
    public static implicit operator DumpColor(Color color);
}

Creating DumpColor Instances

From Hex String

// Using constructor
var color1 = new DumpColor("#FF5733");

// Using factory method
var color2 = DumpColor.FromHexString("#FF5733");

// Using implicit conversion (most common)
DumpColor color3 = "#FF5733";

From System.Drawing.Color

using System.Drawing;

// Using constructor
var color1 = new DumpColor(Color.Red);

// Using implicit conversion
DumpColor color2 = Color.Blue;

Hex String Format

Dumpify accepts standard hex color formats:

// With hash prefix (recommended)
"#FF5733"
"#ff5733"  // Case insensitive

// Named colors (supported by System.Drawing)
"Red"
"Blue"
"Green"

Usage with ColorConfig

The most common use of DumpColor is configuring colors in ColorConfig:

// Implicit conversion from string - cleanest syntax
DumpConfig.Default.ColorConfig.NullValueColor = "#FF6B6B";
DumpConfig.Default.ColorConfig.PropertyValueColor = "#98C379";
DumpConfig.Default.ColorConfig.TypeNameColor = "#E5C07B";

// Using System.Drawing.Color
DumpConfig.Default.ColorConfig.MetadataInfoColor = Color.Green;
DumpConfig.Default.ColorConfig.MetadataErrorColor = Color.Red;

// Explicit construction
DumpConfig.Default.ColorConfig.ColumnNameColor = new DumpColor("#61AFEF");

Implicit Conversions

DumpColor supports implicit conversion from both string and System.Drawing.Color, making it convenient to use:

// All of these are equivalent
ColorConfig config = new ColorConfig();

config.NullValueColor = "#FF0000";                    // string
config.NullValueColor = new DumpColor("#FF0000");     // explicit
config.NullValueColor = Color.Red;                    // Color
config.NullValueColor = new DumpColor(Color.Red);    // explicit from Color

Error Handling

Invalid hex strings will throw an exception:

// This will throw
var invalid = new DumpColor("not-a-color");

// This will also throw
DumpColor color = "invalid";

Valid formats:

  • #RGB (short form)
  • #RRGGBB (full form)
  • Named colors: Red, Blue, Green, etc.

Internal Properties

While not part of the public API, DumpColor internally maintains:

  • Color - The System.Drawing.Color representation
  • HexString - The hex string representation

These are used internally by Dumpify’s rendering system.


Examples

Configure Multiple Colors

// Set up a dark theme
var colorConfig = DumpConfig.Default.ColorConfig;

colorConfig.NullValueColor = "#6B7280";       // Gray for null
colorConfig.PropertyValueColor = "#10B981";   // Green for property values
colorConfig.PropertyNameColor = "#3B82F6";    // Blue for property names
colorConfig.TypeNameColor = "#E5C07B";        // Yellow for type names
colorConfig.ColumnNameColor = "#61AFEF";      // Blue for column headers
colorConfig.MetadataInfoColor = "#8B5CF6";    // Purple for metadata
colorConfig.LabelValueColor = "#D7AFD7";      // Pink for labels

Using System.Drawing.Color Constants

using System.Drawing;

var colorConfig = DumpConfig.Default.ColorConfig;

colorConfig.NullValueColor = Color.Gray;
colorConfig.PropertyValueColor = Color.ForestGreen;
colorConfig.TypeNameColor = Color.DarkGoldenrod;
colorConfig.MetadataInfoColor = Color.Green;
colorConfig.MetadataErrorColor = Color.Red;

Per-Call Color Override

var customColors = new ColorConfig
{
    NullValueColor = "#FF0000",  // Highlight nulls in red
};

myObject.Dump(colors: customColors);

See Also