From f60f15ee246218193603ed1132c24625b4a38bc3 Mon Sep 17 00:00:00 2001 From: Jonathan Algar <93204286+jonathanalgar@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:11:14 +0000 Subject: [PATCH] first shot --- src/CustomCode-Analyzer/Analyzer.cs | 7 ++++++- .../CustomCode-Analyzer.Tests/AnalyzerTests.cs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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()