Skip to content

Commit e688380

Browse files
Fix false positive for UnsupportedTypeMapping on byte array fields (#31)
1 parent 42ad546 commit e688380

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/CustomCode-Analyzer/Analyzer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,14 @@ private static bool HasIncompatibleDataTypeMapping(ITypeSymbol type, TypedConsta
14431443
return true;
14441444
}
14451445

1446+
// If the type is an array, reconstruct the expected type name ("Byte[]" from type "Byte")
1447+
string actualTypeName = type is IArrayTypeSymbol arrayType
1448+
? arrayType.ElementType.Name + "[]"
1449+
: type.Name;
1450+
14461451
// Finally, compare the actual .NET type name with the expected
14471452
// .NET type name from TypeMappingHelper
1448-
return !type.Name.Equals(expectedDotNetType, StringComparison.OrdinalIgnoreCase);
1453+
return !actualTypeName.Equals(expectedDotNetType, StringComparison.OrdinalIgnoreCase);
14491454
}
14501455
}
14511456
}

tests/CustomCode-Analyzer.Tests/AnalyzerTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,24 @@ await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
13181318
);
13191319
}
13201320

1321+
[TestMethod]
1322+
public async Task UnsupportedTypeMappingRule_ArrayOfBytes_NoDiagnostic()
1323+
{
1324+
var source =
1325+
@"
1326+
[OSStructure]
1327+
public struct TestStruct
1328+
{
1329+
[OSStructureField(DataType = OSDataType.BinaryData)]
1330+
public byte[] RawBytes;
1331+
}";
1332+
await CSharpAnalyzerVerifier<Analyzer>.VerifyAnalyzerAsync(
1333+
source,
1334+
TestContext,
1335+
skipSDKreference: false
1336+
);
1337+
}
1338+
13211339
// --------------- MissingPublicImplementationRule (OS-ELG-MODL-05018) --------
13221340
[TestMethod]
13231341
public async Task MissingPublicImplementationRule_InGlobalScope_ReportsWarning()

0 commit comments

Comments
 (0)