Skip to content

Commit 79c83e9

Browse files
committed
Removed MarshalAs on bool fields for .NET 7+
Contributes to #237
1 parent b52f30d commit 79c83e9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Diff for: Biohazrd.CSharp/CSharpLibraryGenerator.Fields.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Biohazrd.Expressions;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32
using System.Linq;
43
using static Biohazrd.CSharp.CSharpCodeWriter;
54

@@ -17,7 +16,7 @@ private void StartField(TranslatedField field)
1716
// Apply MarshalAs to boolean fields
1817
// This might not strictly be necessary since our struct has an explicit layout, but we do it anyway for the sake of sanity.
1918
// (The marshaler definitely still runs on bools in explicit layouts, but it's not immediately clear if it is trying to interpret the memory as a 4-byte or 1-byte bool.)
20-
if (field is TranslatedNormalField { Type: CSharpBuiltinTypeReference cSharpType } && cSharpType.Type == CSharpBuiltinType.Bool)
19+
if (Options.TargetRuntime < TargetRuntime.Net7 && field is TranslatedNormalField { Type: CSharpBuiltinTypeReference cSharpType } && cSharpType.Type == CSharpBuiltinType.Bool)
2120
{ Writer.Write($"[MarshalAs(UnmanagedType.I1)] "); }
2221

2322
Writer.Write($"{field.Accessibility.ToCSharpKeyword()} ");

0 commit comments

Comments
 (0)