1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ #nullable enable
5
+
4
6
using System ;
5
7
using System . Collections . Generic ;
6
8
using System . Linq ;
@@ -26,13 +28,25 @@ internal static class TemplateGroupDisplay
26
28
/// <param name="language">language from the command input.</param>
27
29
/// <param name="defaultLanguage">default language.</param>
28
30
/// <returns></returns>
29
- internal static IReadOnlyList < TemplateGroupTableRow > GetTemplateGroupsForListDisplay ( IEnumerable < ITemplateInfo > templateList , string language , string defaultLanguage )
31
+ internal static IReadOnlyList < TemplateGroupTableRow > GetTemplateGroupsForListDisplay ( IEnumerable < ITemplateInfo > templateList , string ? language , string ? defaultLanguage )
30
32
{
31
33
List < TemplateGroupTableRow > templateGroupsForDisplay = new List < TemplateGroupTableRow > ( ) ;
32
- IEnumerable < IGrouping < string , ITemplateInfo > > groupedTemplateList = templateList . GroupBy ( x => x . GroupIdentity , x => ! string . IsNullOrEmpty ( x . GroupIdentity ) , StringComparer . OrdinalIgnoreCase ) ;
33
- foreach ( IGrouping < string , ITemplateInfo > grouping in groupedTemplateList )
34
+ IEnumerable < IGrouping < string ? , ITemplateInfo > > groupedTemplateList = templateList . GroupBy ( x => x . GroupIdentity , x => ! string . IsNullOrEmpty ( x . GroupIdentity ) , StringComparer . OrdinalIgnoreCase ) ;
35
+ foreach ( IGrouping < string ? , ITemplateInfo > templateGroup in groupedTemplateList )
34
36
{
35
- templateGroupsForDisplay . Add ( GetTemplateGroupRow ( grouping , language , defaultLanguage ) ) ;
37
+ ITemplateInfo highestPrecedenceTemplate = templateGroup . OrderByDescending ( x => x . Precedence ) . First ( ) ;
38
+ string shortNames = string . Join ( "," , templateGroup . SelectMany ( t => t . ShortNameList ) . Distinct ( StringComparer . OrdinalIgnoreCase ) ) ;
39
+
40
+ TemplateGroupTableRow groupDisplayInfo = new TemplateGroupTableRow
41
+ {
42
+ Name = highestPrecedenceTemplate . Name ,
43
+ ShortNames = shortNames ,
44
+ Languages = string . Join ( "," , GetLanguagesToDisplay ( templateGroup , language , defaultLanguage ) ) ,
45
+ Classifications = highestPrecedenceTemplate . Classifications != null ? string . Join ( "/" , highestPrecedenceTemplate . Classifications ) : string . Empty ,
46
+ Author = highestPrecedenceTemplate . Author ?? string . Empty ,
47
+ Type = highestPrecedenceTemplate . GetTemplateType ( ) ?? string . Empty
48
+ } ;
49
+ templateGroupsForDisplay . Add ( groupDisplayInfo ) ;
36
50
}
37
51
38
52
return templateGroupsForDisplay ;
@@ -48,28 +62,38 @@ internal static IReadOnlyList<TemplateGroupTableRow> GetTemplateGroupsForListDis
48
62
/// - Author
49
63
/// - Type.
50
64
/// </summary>
51
- /// <param name="templateList ">list of template groups to be displayed.</param>
65
+ /// <param name="templateGroupList ">list of template groups to be displayed.</param>
52
66
/// <param name="language">language from the command input.</param>
53
67
/// <param name="defaultLanguage">default language.</param>
54
68
/// <returns></returns>
55
- internal static IReadOnlyList < TemplateGroupTableRow > GetTemplateGroupsForListDisplay ( IReadOnlyCollection < TemplateGroup > templateGroupList , string language , string defaultLanguage )
69
+ internal static IReadOnlyList < TemplateGroupTableRow > GetTemplateGroupsForListDisplay ( IReadOnlyCollection < TemplateGroup > templateGroupList , string ? language , string ? defaultLanguage )
56
70
{
57
71
List < TemplateGroupTableRow > templateGroupsForDisplay = new List < TemplateGroupTableRow > ( ) ;
58
72
foreach ( TemplateGroup templateGroup in templateGroupList )
59
73
{
60
- templateGroupsForDisplay . Add ( GetTemplateGroupRow ( templateGroup . Templates . Select ( mi => mi . Info ) , language , defaultLanguage ) ) ;
74
+ ITemplateInfo highestPrecedenceTemplate = templateGroup . Templates . OrderByDescending ( x => x . Info . Precedence ) . First ( ) . Info ;
75
+ TemplateGroupTableRow groupDisplayInfo = new TemplateGroupTableRow
76
+ {
77
+ Name = highestPrecedenceTemplate . Name ,
78
+ ShortNames = string . Join ( "," , templateGroup . ShortNames ) ,
79
+ Languages = string . Join ( "," , GetLanguagesToDisplay ( templateGroup . Templates . Select ( t => t . Info ) , language , defaultLanguage ) ) ,
80
+ Classifications = highestPrecedenceTemplate . Classifications != null ? string . Join ( "/" , highestPrecedenceTemplate . Classifications ) : string . Empty ,
81
+ Author = highestPrecedenceTemplate . Author ?? string . Empty ,
82
+ Type = highestPrecedenceTemplate . GetTemplateType ( ) ?? string . Empty
83
+ } ;
84
+ templateGroupsForDisplay . Add ( groupDisplayInfo ) ;
61
85
}
62
86
return templateGroupsForDisplay ;
63
87
}
64
88
65
- private static TemplateGroupTableRow GetTemplateGroupRow ( IEnumerable < ITemplateInfo > templateGroup , string language , string defaultLanguage )
89
+ private static IEnumerable < string > GetLanguagesToDisplay ( IEnumerable < ITemplateInfo > templateGroup , string ? language , string ? defaultLanguage )
66
90
{
67
- List < string > languageForDisplay = new List < string > ( ) ;
91
+ List < string > languagesForDisplay = new List < string > ( ) ;
68
92
HashSet < string > uniqueLanguages = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
69
93
string defaultLanguageDisplay = string . Empty ;
70
94
foreach ( ITemplateInfo template in templateGroup )
71
95
{
72
- string lang = template . GetLanguage ( ) ;
96
+ string ? lang = template . GetLanguage ( ) ;
73
97
if ( string . IsNullOrWhiteSpace ( lang ) )
74
98
{
75
99
continue ;
@@ -85,29 +109,16 @@ private static TemplateGroupTableRow GetTemplateGroupRow(IEnumerable<ITemplateIn
85
109
}
86
110
else
87
111
{
88
- languageForDisplay . Add ( lang ) ;
112
+ languagesForDisplay . Add ( lang ) ;
89
113
}
90
114
}
91
115
92
- languageForDisplay . Sort ( StringComparer . OrdinalIgnoreCase ) ;
116
+ languagesForDisplay . Sort ( StringComparer . OrdinalIgnoreCase ) ;
93
117
if ( ! string . IsNullOrEmpty ( defaultLanguageDisplay ) )
94
118
{
95
- languageForDisplay . Insert ( 0 , defaultLanguageDisplay ) ;
119
+ languagesForDisplay . Insert ( 0 , defaultLanguageDisplay ) ;
96
120
}
97
-
98
- ITemplateInfo highestPrecedenceTemplate = templateGroup . OrderByDescending ( x => x . Precedence ) . First ( ) ;
99
- string shortName = highestPrecedenceTemplate . ShortNameList [ 0 ] ;
100
-
101
- TemplateGroupTableRow groupDisplayInfo = new TemplateGroupTableRow
102
- {
103
- Name = highestPrecedenceTemplate . Name ,
104
- ShortName = shortName ,
105
- Languages = string . Join ( "," , languageForDisplay ) ,
106
- Classifications = highestPrecedenceTemplate . Classifications != null ? string . Join ( "/" , highestPrecedenceTemplate . Classifications ) : null ,
107
- Author = highestPrecedenceTemplate . Author ,
108
- Type = highestPrecedenceTemplate . GetTemplateType ( ) ?? string . Empty
109
- } ;
110
- return groupDisplayInfo ;
121
+ return languagesForDisplay ;
111
122
}
112
123
}
113
124
}
0 commit comments