Skip to content

Instantly share code, notes, and snippets.

@MithrilMan
Last active January 21, 2020 14:47
Show Gist options
  • Select an option

  • Save MithrilMan/7706a284253b5fe0e0bc6325c1ffa7bc to your computer and use it in GitHub Desktop.

Select an option

Save MithrilMan/7706a284253b5fe0e0bc6325c1ffa7bc to your computer and use it in GitHub Desktop.
LINQPad generic extension to dump number informations
public static class ObjectExtensions
{
public static string ToHex(this object val, int size)
{
return Convert.ToInt64(val).ToString("X2").PadLeft(size * 2, '0'); ;
}
public static string ToBitString(this object val, int size)
{
return Convert.ToString((Convert.ToInt64(val)), 2).PadLeft(size * 8, '0');
}
public static T Show<T>(this T val, string text = null)
{
int size = Marshal.SizeOf(val);
long convertedVal = Convert.ToInt64(val);
new
{
Numeric = convertedVal.ToString("N"),
HexString = convertedVal.ToHex(size),
BitString = convertedVal.ToBitString(size),
}.Dump(text);
return val;
}
}
@MithrilMan

MithrilMan commented Jan 21, 2020

Copy link
Copy Markdown
Author

example
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment