PopupBox For Debug Only

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,
  1. using System;  
  2. using System.Net.Mail;  
  3. using System.Windows.Forms;  
  4.   
  5. namespace DebugPopup  
  6. {  
  7.     public partial class FrmSample : Form  
  8.     {  
  9.         public FrmSample() => InitializeComponent();  
  10.   
  11.         private void Form1_Load(object sender, EventArgs e)  
  12.         {  
  13.             var eml = new MailAddress("[email protected]""test");  
  14.   
  15.             eml.PopupBox();  
  16.   
  17.             var n = 0;  
  18.   
  19.             n.PopupBox();  
  20.   
  21.             Handle.PopupBox();  
  22.   
  23.             decimal.Zero.PopupBox(n==0, "n is equals zero!");  
  24.           
  25.         }  
  26.   
  27.         private void button1_Click(object sender, EventArgs e)  
  28.         {  
  29.             ((Button)sender).PopupBox();  
  30.         }  
  31.     }  
  32. }  
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,
  1. using System.Windows.Forms;  
  2. using System.Net.Mail;  
  3. using System.Diagnostics;  
  4.   
  5. /// <summary>  
  6. /// Author: Jefferson Saul G. Motta  
  7. /// 10-24-2019 20:50  
  8. /// Uses the System  
  9. /// </summary>  
  10. namespace System  
  11. {  
  12.   
  13.     /// <summary>    
  14.     /// This is my real code that I make to debug easly  
  15.     /// You can copy to .NET Core as Well  
  16.     /// If you are debugging in a local IIS (ASP.NET WebForms)  
  17.     /// The popup will raises too  
  18.     /// C# 7.3 and C# 8.0  
  19.     /// About extensions: http://www.c-sharpcorner.com/blogs/extension-method-in-c-sharp3  
  20.     /// </summary>  
  21.     public static class ExtensionMethodStrings  
  22.     {  
  23.   
  24.           
  25.         /// <summary>  
  26.         /// Popup for int value  
  27.         /// </summary>  
  28.         /// <param name="value"></param>  
  29.         /// <param name="showIf"></param>  
  30.         /// <param name="message"></param>  
  31.         /// <returns></returns>  
  32.         public static bool PopupBox(this int value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  33.           
  34.         /// <summary>  
  35.         /// Popup for decimal value  
  36.         /// </summary>  
  37.         /// <param name="value"></param>  
  38.         /// <param name="showIf"></param>  
  39.         /// <param name="message"></param>  
  40.         /// <returns></returns>  
  41.         public static bool PopupBox(this decimal value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  42.           
  43.         /// <summary>  
  44.         /// Popup for IntPtr value  
  45.         /// </summary>  
  46.         /// <param name="value"></param>  
  47.         /// <param name="showIf"></param>  
  48.         /// <param name="message"></param>  
  49.         /// <returns></returns>  
  50.         public static bool PopupBox(this IntPtr value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);          
  51.           
  52.         /// <summary>  
  53.         /// Popup for double value  
  54.         /// </summary>  
  55.         /// <param name="value"></param>  
  56.         /// <param name="showIf"></param>  
  57.         /// <param name="message"></param>  
  58.         /// <returns></returns>  
  59.         public static bool PopupBox(this double value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  60.           
  61.         /// <summary>  
  62.         /// Popup for long value  
  63.         /// </summary>  
  64.         /// <param name="value"></param>  
  65.         /// <param name="showIf"></param>  
  66.         /// <param name="message"></param>  
  67.         /// <returns></returns>  
  68.         public static bool PopupBox(this long value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  69.           
  70.         /// <summary>  
  71.         /// Popup for string value  
  72.         /// </summary>  
  73.         /// <param name="value"></param>  
  74.         /// <param name="showIf"></param>  
  75.         /// <param name="message"></param>  
  76.         /// <returns></returns>  
  77.         public static bool PopupBox(this string value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  78.           
  79.           
  80.         /// <summary>  
  81.         /// Popup for string value if contem a string  
  82.         /// </summary>  
  83.         /// <param name="value"></param>  
  84.         /// <param name="contem"></param>  
  85.         /// <param name="message"></param>  
  86.         /// <returns></returns>  
  87.         public static bool PopupBox(this string value, in string contem, in string message = "") => PopupIt($"Value: {value}", value.ContemUpper(contem), message);          
  88.           
  89.         /// <summary>  
  90.         /// Popup for bool value  
  91.         /// </summary>  
  92.         /// <param name="value"></param>  
  93.         /// <param name="showIf"></param>  
  94.         /// <param name="message"></param>  
  95.         /// <returns></returns>  
  96.         public static bool PopupBox(this bool value, in bool showIf = truein string message = "") => PopupIt($"Value: {value}", showIf, message);  
  97.   
  98.         /// <summary>  
  99.         /// Check if exist comparing uppper text  
  100.         /// </summary>  
  101.         /// <param name="value"></param>  
  102.         /// <param name="text"></param>  
  103.         /// <returns></returns>  
  104.         private static bool ContemUpper(this string value, string text) => string.IsNullOrEmpty(value) || string.IsNullOrEmpty(text) ? false : value.ToUpper().IndexOf(text.ToUpper()) != -1;  
  105.   
  106.   
  107.         /// <summary>  
  108.         /// Sample  
  109.         /// You can add another controls or objects  
  110.         /// </summary>  
  111.         /// <param name="button"></param>  
  112.         /// <param name="showIf"></param>  
  113.         /// <returns></returns>  
  114.         public static bool PopupBox(this Button button, in bool showIf = true) => PopupIt(button.Text, showIf);  
  115.   
  116.         /// <summary>  
  117.         /// Sample  
  118.         /// You can add another controls or objects  
  119.         /// Test with MailAddress  
  120.         /// </summary>  
  121.         /// <param name="eml"></param>  
  122.         /// <param name="showIf"></param>  
  123.         /// <returns></returns>  
  124.         public static bool PopupBox(this MailAddress eml, in bool showIf = true) => PopupIt(eml.Address, showIf);  
  125.   
  126.         /// <summary>  
  127.         /// Add the label if value not is empty  
  128.         /// </summary>  
  129.         /// <param name="value"></param>  
  130.         /// <param name="label"></param>  
  131.         /// <returns></returns>  
  132.         private static string LabelIfNotEmpty(this string value, string label) => string.IsNullOrEmpty(value) ? "" : $"{label}:{value}";  
  133.   
  134.         /// <summary>  
  135.         /// Show popup only for DEBUG  
  136.         /// </summary>  
  137.         /// <param name="message"></param>  
  138.         /// <param name="showIf"></param>  
  139.         /// <param name="messageExtra"></param>  
  140.         /// <returns></returns>  
  141.         private static bool PopupIt(string message, in bool showIf = truein string messageExtra = "")  
  142.  
  143. #if (DEBUG)  
  144.         {  
  145.             // Show popup if true  
  146.             if (showIf)  
  147.             {  
  148.                 Debug.WriteLine($"{messageExtra.LabelIfNotEmpty("Extra message:")}{message}");  
  149.               
  150.                 // Optional:  
  151.                 MessageBox.Show($"{messageExtra.LabelIfNotEmpty("Extra message:")}{message}");  
  152.               
  153.             }  
  154.             // showIf   
  155.             return showIf;  
  156.         }  
  157. #else  
  158.             // on Releases returns false  
  159.             => false;  
  160.  
  161. #endif  
  162.   
  163.     }  
  164.   
  165. }  
You can contribute with the community on the GitHub
 
This is my first GitHub free project, I hope you enjoy it.
 
Happy coding.