diff --git a/src/CustomCode-Analyzer/Analyzer.cs b/src/CustomCode-Analyzer/Analyzer.cs index 9e3ff44..f272e10 100644 --- a/src/CustomCode-Analyzer/Analyzer.cs +++ b/src/CustomCode-Analyzer/Analyzer.cs @@ -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)) { diff --git a/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs b/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs index 9036836..d72db78 100644 --- a/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs +++ b/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs @@ -1136,6 +1136,30 @@ await CSharpAnalyzerVerifier.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.VerifyAnalyzerAsync( + test, + TestContext, + skipSDKreference: false + ); + } + // --------------- ParameterByReferenceRule (OS-ELG-MODL-05016) ------------ [TestMethod] public async Task ParameterByReferenceRule_InGlobalScope_ReportsWarning()