diff --git a/src/CustomCode-Analyzer/Analyzer.cs b/src/CustomCode-Analyzer/Analyzer.cs index 05ce6a9..52b282e 100644 --- a/src/CustomCode-Analyzer/Analyzer.cs +++ b/src/CustomCode-Analyzer/Analyzer.cs @@ -1408,9 +1408,14 @@ private static bool HasIncompatibleDataTypeMapping(ITypeSymbol type, TypedConsta return true; } + // If the type is an array, reconstruct the expected type name ("Byte[]" from type "Byte") + string actualTypeName = type is IArrayTypeSymbol arrayType + ? arrayType.ElementType.Name + "[]" + : type.Name; + // Finally, compare the actual .NET type name with the expected // .NET type name from TypeMappingHelper - return !type.Name.Equals(expectedDotNetType, StringComparison.OrdinalIgnoreCase); + return !actualTypeName.Equals(expectedDotNetType, StringComparison.OrdinalIgnoreCase); } } } diff --git a/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs b/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs index 4828f49..e8bdceb 100644 --- a/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs +++ b/tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs @@ -1318,6 +1318,24 @@ await CSharpAnalyzerVerifier.VerifyAnalyzerAsync( ); } + [TestMethod] + public async Task UnsupportedTypeMappingRule_ArrayOfBytes_NoDiagnostic() + { + var source = + @" +[OSStructure] +public struct TestStruct +{ + [OSStructureField(DataType = OSDataType.BinaryData)] + public byte[] RawBytes; +}"; + await CSharpAnalyzerVerifier.VerifyAnalyzerAsync( + source, + TestContext, + skipSDKreference: false + ); + } + // --------------- MissingPublicImplementationRule (OS-ELG-MODL-05018) -------- [TestMethod] public async Task MissingPublicImplementationRule_InGlobalScope_ReportsWarning()