Skip to content

Commit 089ec9e

Browse files
committed
限制 RawArguments 更多类型
1 parent 48ee127 commit 089ec9e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/DotNetCampus.CommandLine.Analyzer/Analyzers/FindOptionPropertyTypeAnalyzer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ namespace DotNetCampus.CommandLine.Analyzers;
99
[DiagnosticAnalyzer(LanguageNames.CSharp)]
1010
public class FindOptionPropertyTypeAnalyzer : DiagnosticAnalyzer
1111
{
12-
private readonly ImmutableHashSet<string> _nonGenericTypeNames =
12+
private readonly HashSet<string> _nonGenericTypeNames =
1313
[
1414
"String", "string", "Boolean", "bool", "Byte", "byte", "Int16", "short", "UInt16", "ushort", "Int32", "int", "UInt32", "uint", "Int64", "long",
1515
"UInt64", "ulong", "Single", "float", "Double", "double", "Decimal", "decimal", "IList", "ICollection", "IEnumerable",
1616
];
1717

18-
private readonly ImmutableHashSet<string> _oneGenericTypeNames =
18+
private readonly HashSet<string> _oneGenericTypeNames =
1919
[
2020
"[]", "ImmutableArray", "List", "IList", "IReadOnlyList", "ImmutableHashSet", "Collection", "ICollection", "IReadOnlyCollection", "IEnumerable",
2121
];
2222

23-
private readonly ImmutableHashSet<string> _twoGenericTypeNames =
23+
private readonly HashSet<string> _rawArgumentsGenericTypeNames =
24+
[
25+
"[]", "IList", "IReadOnlyList", "ICollection", "IReadOnlyCollection", "IEnumerable",
26+
];
27+
28+
private readonly HashSet<string> _twoGenericTypeNames =
2429
["ImmutableDictionary", "Dictionary", "IDictionary", "IReadOnlyDictionary", "KeyValuePair"];
2530

26-
private readonly ImmutableHashSet<string> _genericKeyArgumentTypeNames = ["String", "string"];
27-
private readonly ImmutableHashSet<string> _genericArgumentTypeNames = ["String", "string"];
31+
private readonly HashSet<string> _genericKeyArgumentTypeNames = ["String", "string"];
32+
private readonly HashSet<string> _genericArgumentTypeNames = ["String", "string"];
2833

2934
/// <summary>
3035
/// Supported diagnostics.
@@ -182,7 +187,7 @@ private bool AnalyzeRawArgumentsPropertyType(SemanticModel semanticModel, Proper
182187
string typeName = GetTypeName(propertyTypeSyntax);
183188
var (genericType0, genericType1) = GetGenericTypeNames(propertyTypeSyntax);
184189

185-
if (IsOneGenericType(typeName)
190+
if (IsRawArgumentsGenericType(typeName)
186191
&& genericType0 != null
187192
&& IsGenericArgumentType(genericType0))
188193
{
@@ -265,6 +270,9 @@ private bool IsNonGenericType(string typeName)
265270
private bool IsOneGenericType(string typeName)
266271
=> _oneGenericTypeNames.Contains(typeName, StringComparer.Ordinal);
267272

273+
private bool IsRawArgumentsGenericType(string typeName)
274+
=> _rawArgumentsGenericTypeNames.Contains(typeName, StringComparer.Ordinal);
275+
268276
private bool IsTwoGenericType(string typeName)
269277
=> _twoGenericTypeNames.Contains(typeName, StringComparer.Ordinal);
270278

0 commit comments

Comments
 (0)