Skip to content

Commit f0107a8

Browse files
committed
first shot
1 parent e688380 commit f0107a8

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/CustomCode-Analyzer/Analyzer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,14 @@ private static bool IsValidParameterType(ITypeSymbol typeSymbol, Compilation com
13731373
return false;
13741374
}
13751375

1376+
// If the type is nullable, unwrap it and check the underlying type
1377+
if (typeSymbol is INamedTypeSymbol named &&
1378+
named.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T &&
1379+
named.TypeArguments.Length == 1)
1380+
{
1381+
typeSymbol = named.TypeArguments[0];
1382+
}
1383+
13761384
// Check for primitive or special types
13771385
if (ValidParameterSpecialTypes.Contains(typeSymbol.SpecialType))
13781386
{

tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,30 @@ await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
11361136
);
11371137
}
11381138

1139+
[TestMethod]
1140+
public async Task UnsupportedParameterTypeRule_InGlobalScope_PublicField_NullableStruct_NoWarning()
1141+
{
1142+
var test =
1143+
@"
1144+
[OSStructure]
1145+
public struct NestedStructure
1146+
{
1147+
public int Value;
1148+
}
1149+
1150+
[OSStructure]
1151+
public struct MyStructure
1152+
{
1153+
public NestedStructure? NullableNested; // Nullable struct OK
1154+
}
1155+
";
1156+
await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
1157+
test,
1158+
TestContext,
1159+
skipSDKreference: false
1160+
);
1161+
}
1162+
11391163
// --------------- ParameterByReferenceRule (OS-ELG-MODL-05016) ------------
11401164
[TestMethod]
11411165
public async Task ParameterByReferenceRule_InGlobalScope_ReportsWarning()

0 commit comments

Comments
 (0)