Skip to content

Commit

Permalink
Removed MarshalAs on bool fields for .NET 7+
Browse files Browse the repository at this point in the history
Relates to #237
  • Loading branch information
PathogenDavid committed Feb 15, 2022
1 parent 6c820d7 commit c540791
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Biohazrd.CSharp/CSharpLibraryGenerator.Fields.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Biohazrd.Expressions;
using System.Diagnostics;
using System.Diagnostics;
using System.Linq;
using static Biohazrd.CSharp.CSharpCodeWriter;

Expand All @@ -17,7 +16,7 @@ private void StartField(TranslatedField field)
// Apply MarshalAs to boolean fields
// This might not strictly be necessary since our struct has an explicit layout, but we do it anyway for the sake of sanity.
// (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.)
if (field is TranslatedNormalField { Type: CSharpBuiltinTypeReference cSharpType } && cSharpType.Type == CSharpBuiltinType.Bool)
if (Options.TargetRuntime < TargetRuntime.Net7 && field is TranslatedNormalField { Type: CSharpBuiltinTypeReference cSharpType } && cSharpType.Type == CSharpBuiltinType.Bool)
{ Writer.Write($"[MarshalAs(UnmanagedType.I1)] "); }

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

0 comments on commit c540791

Please sign in to comment.