When debugging I feel a need to popup values from variables.
I know that Visual Studio is cool but I feel the need to use it just typing.
So I design an extension method to make it easy.
You can add your custom objects, or Windows objects, and make a clause to show it or not.
The message is shown only in DEBUG time.
See this sample,
- using System;
- using System.Net.Mail;
- using System.Windows.Forms;
-
- namespace DebugPopup
- {
- public partial class FrmSample : Form
- {
- public FrmSample() => InitializeComponent();
-
- private void Form1_Load(object sender, EventArgs e)
- {
- var eml = new MailAddress("[email protected]", "test");
-
- eml.PopupBox();
-
- var n = 0;
-
- n.PopupBox();
-
- Handle.PopupBox();
-
- decimal.Zero.PopupBox(n==0, "n is equals zero!");
-
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- ((Button)sender).PopupBox();
- }
- }
- }
It 's an extension method that you only need to add.PopupBox() from the Visual Studio property menu.
You can add custom types and the message will be shown only in DEBUG mode, I mean that in production there will be no message.
This is the main code,
- using System.Windows.Forms;
- using System.Net.Mail;
- using System.Diagnostics;
-
-
-
-
-
-
- namespace System
- {
-
-
-
-
-
-
-
-
-
- public static class ExtensionMethodStrings
- {
-
-
-
-
-
-
-
-
-
- public static bool PopupBox(this int value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this decimal value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this IntPtr value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this double value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this long value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this string value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
-
-
- public static bool PopupBox(this string value, in string contem, in string message = "") => PopupIt($"Value: {value}", value.ContemUpper(contem), message);
-
-
-
-
-
-
-
-
- public static bool PopupBox(this bool value, in bool showIf = true, in string message = "") => PopupIt($"Value: {value}", showIf, message);
-
-
-
-
-
-
-
- private static bool ContemUpper(this string value, string text) => string.IsNullOrEmpty(value) || string.IsNullOrEmpty(text) ? false : value.ToUpper().IndexOf(text.ToUpper()) != -1;
-
-
-
-
-
-
-
-
-
- public static bool PopupBox(this Button button, in bool showIf = true) => PopupIt(button.Text, showIf);
-
-
-
-
-
-
-
-
-
- public static bool PopupBox(this MailAddress eml, in bool showIf = true) => PopupIt(eml.Address, showIf);
-
-
-
-
-
-
-
- private static string LabelIfNotEmpty(this string value, string label) => string.IsNullOrEmpty(value) ? "" : $"{label}:{value}";
-
-
-
-
-
-
-
-
- private static bool PopupIt(string message, in bool showIf = true, in string messageExtra = "")
-
- #if (DEBUG)
- {
-
- if (showIf)
- {
- Debug.WriteLine($"{messageExtra.LabelIfNotEmpty("Extra message:")}{message}");
-
-
- MessageBox.Show($"{messageExtra.LabelIfNotEmpty("Extra message:")}{message}");
-
- }
-
- return showIf;
- }
- #else
-
- => false;
-
- #endif
-
- }
-
- }
You can contribute with the community on the
GitHub
This is my first GitHub free project, I hope you enjoy it.
Happy coding.