Last active
January 21, 2020 14:47
-
-
Save MithrilMan/7706a284253b5fe0e0bc6325c1ffa7bc to your computer and use it in GitHub Desktop.
LINQPad generic extension to dump number informations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example
