Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CustomCode-Analyzer/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,16 @@ private static bool IsValidParameterType(ITypeSymbol typeSymbol, Compilation com
return false;
}

// If the type is nullable, unwrap it and check the underlying type
if (
typeSymbol is INamedTypeSymbol named
&& named.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T
&& named.TypeArguments.Length == 1
)
{
typeSymbol = named.TypeArguments[0];
}

// Check for primitive or special types
if (ValidParameterSpecialTypes.Contains(typeSymbol.SpecialType))
{
Expand Down
24 changes: 24 additions & 0 deletions tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,30 @@ await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
);
}

[TestMethod]
public async Task UnsupportedParameterTypeRule_InGlobalScope_PublicField_NullableStruct_NoWarning()
{
var test =
@"
[OSStructure]
public struct NestedStructure
{
public int Value;
}

[OSStructure]
public struct MyStructure
{
public NestedStructure? NullableNested; // Nullable struct OK
}
";
await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
test,
TestContext,
skipSDKreference: false
);
}

// --------------- ParameterByReferenceRule (OS-ELG-MODL-05016) ------------
[TestMethod]
public async Task ParameterByReferenceRule_InGlobalScope_ReportsWarning()
Expand Down