Skip to content

Instantly share code, notes, and snippets.

@tmori3y2
Created November 14, 2016 14:11
Show Gist options
  • Save tmori3y2/6cc1001377946491ef8e2a98eb08933d to your computer and use it in GitHub Desktop.
Save tmori3y2/6cc1001377946491ef8e2a98eb08933d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program
{
public static void Main()
{
var text = "Hello World";
text.Dump(1);
new int[] {1, 2, 3}.DumpArray(2);
new float[] {1.0f, 2.0f, 3.0f}.Select(x => x.ToString("F")).DumpArray(3, typeof(float));
}
public static void Dump<T>(this T value, int line)
{
Console.WriteLine("{0, 5}: {1}", line, value.ToString());
}
public static void Dump<T>(this T value)
{
Console.WriteLine(value.ToString());
}
public static void DumpArray<T>(this IEnumerable<T> value, int line)
{
Console.Write("{0, 5}: IEnumerable<{1}>\n +", line, typeof(T).Name);
Console.WriteLine(string.Join("\n +", value.Select(x => x.ToString())));
}
public static void DumpArray<T>(this IEnumerable<T> value)
{
Console.Write("IEnumerable<{0}>\n +", typeof(T).Name);
Console.WriteLine(string.Join("\n +", value.Select(x => x.ToString())));
}
public static void DumpArray(this IEnumerable<string> value, int line, Type type)
{
Console.Write("{0, 5}: IEnumerable<{1}>\n +", line, type.Name);
Console.WriteLine(string.Join("\n +", value.Select(x => x.ToString())));
}
public static void DumpArray(this IEnumerable<string> value, Type type)
{
Console.Write("IEnumerable<{0}>\n +", type.Name);
Console.WriteLine(string.Join("\n +", value.Select(x => x.ToString())));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment