定義
static class DumpExtensions
{
public static void DumpExH1(this string value)
=> DumpWrappedWithTags(value, "h1");
public static void DumpExH2(this string value)
=> DumpWrappedWithTags(value, "h2");
public static void DumpExH3(this string value)
=> DumpWrappedWithTags(value, "h3");
private static void DumpWrappedWithTags(string value, string tag)
{
Util.RawHtml($"<{tag}>{value}</{tag}>").Dump();
}
public static void DumpExColor(this string value, ConsoleColor color = ConsoleColor.Black, ConsoleColor? background = null)
{
var colorStr = $"color: {color}; ";
var backgroundStr = background != null ? $"background-color: {background}; " : "";
Util.WithStyle(value, $"{colorStr}{backgroundStr} display: block; ").Dump();
}
}
利用
void Main()
{
"Header1".DumpExH1();
"Header2".DumpExH2();
"Header3".DumpExH3();
"default".DumpExColor();
"red".DumpExColor(ConsoleColor.Red);
"cyan".DumpExColor(background: ConsoleColor.Cyan);
"blue and yellow".DumpExColor(ConsoleColor.Blue, ConsoleColor.Yellow);
}