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