File tree 2 files changed +51
-0
lines changed
ReportGenerator.Core/Parser/Analysis 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ For further details take a look at LICENSE.txt.
63
63
64
64
CHANGELOG
65
65
66
+ 4.8.6.0
67
+
68
+ * New: Improved name of generic classes (https://github.com/coverlet-coverage/coverlet/issues/1077)
69
+
66
70
4.8.5.0
67
71
68
72
* Fix: # 406: Fixed reference version of McMaster.NETCore.Plugins for package ReportGenerator.Core
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Text . RegularExpressions ;
4
5
5
6
namespace Palmmedia . ReportGenerator . Core . Parser . Analysis
6
7
{
@@ -9,6 +10,11 @@ namespace Palmmedia.ReportGenerator.Core.Parser.Analysis
9
10
/// </summary>
10
11
public class Class
11
12
{
13
+ /// <summary>
14
+ /// Regex to analyze if a class is generic.
15
+ /// </summary>
16
+ private static Regex genericClassRegex = new Regex ( "^(?<Name>.+)`(?<Number>\\ d+)$" , RegexOptions . Compiled ) ;
17
+
12
18
/// <summary>
13
19
/// The object to lock the class add.
14
20
/// </summary>
@@ -38,6 +44,47 @@ internal Class(string name, Assembly assembly)
38
44
{
39
45
this . Name = name ?? throw new ArgumentNullException ( nameof ( name ) ) ;
40
46
this . Assembly = assembly ?? throw new ArgumentNullException ( nameof ( assembly ) ) ;
47
+
48
+ /*
49
+ * Convert class name of generic classes:
50
+ * See: https://github.com/coverlet-coverage/coverlet/issues/1077
51
+ *
52
+ * SomeClass`1 -> SomeClass<T>
53
+ * SomeClass`2 -> SomeClass<T1, T2>
54
+ * SomeClass`3 -> SomeClass<T1, T2, T3>
55
+ */
56
+ if ( name . Contains ( "`" ) )
57
+ {
58
+ Match match = genericClassRegex . Match ( name ) ;
59
+
60
+ if ( match . Success )
61
+ {
62
+ this . Name = match . Groups [ "Name" ] . Value ;
63
+
64
+ int number = int . Parse ( match . Groups [ "Number" ] . Value ) ;
65
+
66
+ if ( number == 1 )
67
+ {
68
+ this . Name += "<T>" ;
69
+ }
70
+ else if ( number > 1 )
71
+ {
72
+ this . Name += "<" ;
73
+
74
+ for ( int i = 1 ; i <= number ; i ++ )
75
+ {
76
+ if ( i > 1 )
77
+ {
78
+ this . Name += ", " ;
79
+ }
80
+
81
+ this . Name += "T" + i ;
82
+ }
83
+
84
+ this . Name += ">" ;
85
+ }
86
+ }
87
+ }
41
88
}
42
89
43
90
/// <summary>
You can’t perform that action at this time.
0 commit comments