XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
关注
0
Fork
0
Star
0
返回提交历史
Modified
XFEExtension.NetCore/XFEExtension.NetCore.csproj
+3
-3
Modified
XFEExtension.NetCore/XUnit/XFECode.cs
+29
-0
XFEstudio/XFEExtension
新增暂停与并行方法,完善异常输出与版本号
升级项目版本至 4.2.4-preview.1.0。 XFECode 新增多种暂停方法(支持自定义文本和指定按键)、并行循环方法(同步与异步)、代码计时方法重载。 测试异常时增加堆栈信息输出,提升调试能力。 补充断言方法注释。
fb2545f
代码差异
2 个文件
+32
-3
@@ -5,7 +5,7 @@
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8
<Version>4.2.3</Version>
8
<Version>4.2.4-preview.1.0</Version>
9
9
<Title>XFEExtension</Title>
10
10
<RepositoryUrl>https://github.com/XFEstudio/XFEExtension</RepositoryUrl>
11
11
<AnalysisLevel>latest</AnalysisLevel>
@@ -20,8 +20,8 @@
20
20
<PackageReleaseNotes>
21
21
## 调整
22
22
23
优化md文档,新增工作流
24
23
新增暂停与并行方法,完善异常输出与版本号
24
25
25
## 新增
26
26
27
27
无
@@ -19,6 +19,7 @@ public abstract class XFECode
19
19
private static bool s_initialized;
20
20
private static bool s_currentMethodIsAsserted;
21
21
private static string s_currentAssertMessage = string.Empty;
22
22
23
#region 暂停
23
24
/// <summary>
24
25
/// 暂停
@@ -32,6 +33,7 @@ public abstract class XFECode
32
33
}
33
34
Console.ReadKey();
34
35
}
36
35
37
/// <summary>
36
38
/// 暂停
37
39
/// </summary>
@@ -41,6 +43,7 @@ public abstract class XFECode
41
43
Console.WriteLine(showText);
42
44
Console.ReadKey();
43
45
}
46
44
47
/// <summary>
45
48
/// 暂停,按下指定按键继续
46
49
/// </summary>
@@ -50,6 +53,7 @@ public abstract class XFECode
50
53
Console.WriteLine($"按 {consoleKey} 键继续");
51
54
while (Console.ReadKey().Key != consoleKey) ;
52
55
}
56
53
57
/// <summary>
54
58
/// 暂停,按下指定按键继续
55
59
/// </summary>
@@ -61,6 +65,7 @@ public abstract class XFECode
61
65
while (Console.ReadKey().Key != consoleKey) ;
62
66
}
63
67
#endregion
68
64
69
/// <summary>
65
70
/// 并行循环指定次数
66
71
/// </summary>
@@ -78,6 +83,7 @@ public abstract class XFECode
78
83
await Task.WhenAll(taskList);
79
84
return taskList;
80
85
}
86
81
87
/// <summary>
82
88
/// 并行循环指定次数
83
89
/// </summary>
@@ -90,6 +96,7 @@ public abstract class XFECode
90
96
await action.StartNewTask();
91
97
}
92
98
}
99
93
100
/// <summary>
94
101
/// 计算一段代码执行所需时间
95
102
/// </summary>
@@ -122,6 +129,7 @@ public abstract class XFECode
122
129
Console.WriteLine($"标识名:{timerName}\t执行批次:{s_cTimeCounter}\t执行时间: {elapsedTime.TotalNanoseconds:F3} 纳秒");
123
130
return elapsedTime;
124
131
}
132
125
133
/// <summary>
126
134
/// 计算一段代码执行所需时间
127
135
/// </summary>
@@ -154,6 +162,7 @@ public abstract class XFECode
154
162
Console.WriteLine($"标识名:{timerName}\t执行批次:{s_cTimeCounter}\t执行时间: {elapsedTime.TotalNanoseconds:F3} 纳秒");
155
163
return elapsedTime;
156
164
}
165
157
166
/// <summary>
158
167
/// 计算一段代码执行所需时间
159
168
/// </summary>
@@ -225,6 +234,7 @@ public abstract class XFECode
225
234
var isSuccessful = true;
226
235
var isResultEqual = true;
227
236
var failedMessage = string.Empty;
237
var failedStackTrace = string.Empty;
228
238
Console.BackgroundColor = ConsoleColor.Black;
229
239
Console.ForegroundColor = methodBorderColor;
230
240
if (isFirstStaticMethod)
@@ -326,6 +336,7 @@ public abstract class XFECode
326
336
{
327
337
isSuccessful = false;
328
338
failedMessage = e.InnerException is not null ? e.InnerException.Message : e.Message;
339
failedStackTrace = e.StackTrace;
329
340
}
330
341
var elapsedTime = timeCounter.Elapsed - selfTimeCounter.Elapsed;
331
342
s_cTimeCounter++;
@@ -379,6 +390,14 @@ public abstract class XFECode
379
390
Console.BackgroundColor = ConsoleColor.Black;
380
391
Console.ForegroundColor = failColor;
381
392
Console.WriteLine($"\t失败原因:{failedMessage}");
393
Console.BackgroundColor = failColor;
394
if (!failedStackTrace.NullOrWhiteSpace)
395
{
396
Console.Write("异常堆栈");
397
Console.BackgroundColor = ConsoleColor.Black;
398
Console.ForegroundColor = failColor;
399
Console.WriteLine($"\t{failedStackTrace}");
400
}
382
401
}
383
402
Console.BackgroundColor = ConsoleColor.Black;
384
403
Console.Write("\n");
@@ -497,6 +516,7 @@ public abstract class XFECode
497
516
var isSuccessful = true;
498
517
var isResultEqual = true;
499
518
var failedMessage = string.Empty;
519
var failedStackTrace = string.Empty;
500
520
Console.BackgroundColor = ConsoleColor.Black;
501
521
Console.ForegroundColor = methodBorderColor;
502
522
if (isFirstMethod)
@@ -598,6 +618,7 @@ public abstract class XFECode
598
618
{
599
619
isSuccessful = false;
600
620
failedMessage = e.InnerException is not null ? e.InnerException.Message : e.Message;
621
failedStackTrace = e.StackTrace;
601
622
}
602
623
var elapsedTime = timeCounter.Elapsed - selfTimeCounter.Elapsed;
603
624
s_cTimeCounter++;
@@ -651,6 +672,13 @@ public abstract class XFECode
651
672
Console.BackgroundColor = ConsoleColor.Black;
652
673
Console.ForegroundColor = failColor;
653
674
Console.WriteLine($"\t失败原因:{failedMessage}");
675
if (!failedStackTrace.NullOrWhiteSpace)
676
{
677
Console.Write("异常堆栈");
678
Console.BackgroundColor = ConsoleColor.Black;
679
Console.ForegroundColor = failColor;
680
Console.WriteLine($"\t{failedStackTrace}");
681
}
654
682
failedList.Add(new MethodAndCounter(method, s_cTimeCounter, failedMessage));
655
683
}
656
684
Console.BackgroundColor = ConsoleColor.Black;
@@ -740,6 +768,7 @@ public abstract class XFECode
740
768
}
741
769
}
742
770
}
771
743
772
/// <summary>
744
773
/// 断言:判断条件为真
745
774
/// </summary>