Browse Source

Simplified the C# marshalling of Boolean fields.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/838/merge
Dimitar Dobrev 8 years ago
parent
commit
dc270ef2a8
  1. 16
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 10
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 5
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

16
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -216,14 +216,6 @@ namespace CppSharp.Generators.CSharp @@ -216,14 +216,6 @@ namespace CppSharp.Generators.CSharp
goto default;
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("{0} != 0", Context.ReturnVarName);
return true;
}
goto default;
default:
Context.Return.Write(Context.ReturnVarName);
return true;
@ -649,14 +641,6 @@ namespace CppSharp.Generators.CSharp @@ -649,14 +641,6 @@ namespace CppSharp.Generators.CSharp
goto default;
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("(byte) ({0} ? 1 : 0)", Context.Parameter.Name);
return true;
}
goto default;
default:
Context.Return.Write(Context.Parameter.Name);
return true;

10
src/Generator/Generators/CSharp/CSharpSources.cs

@ -612,19 +612,13 @@ namespace CppSharp.Generators.CSharp @@ -612,19 +612,13 @@ namespace CppSharp.Generators.CSharp
private void GenerateClassInternalsField(LayoutField field, Class @class)
{
Declaration decl;
field.QualifiedType.Type.TryGetDeclaration(out decl);
var arrayType = field.QualifiedType.Type.Desugar() as ArrayType;
var coreType = field.QualifiedType.Type.Desugar();
if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant)
coreType = arrayType.Type.Desugar();
TypePrinterResult retType = TypePrinter.VisitFieldDecl(
new Field { Name = field.Name, QualifiedType = field.QualifiedType });
PushBlock(BlockKind.Field);
if (field.QualifiedType.Type.Desugar().IsPrimitiveType(PrimitiveType.Bool))
WriteLine("[MarshalAs(UnmanagedType.I1)]");
if (!Options.GenerateSequentialLayout || @class.IsUnion)
WriteLine($"[FieldOffset({field.Offset})]");
Write($"internal {retType}{retType.NameSuffix}");

5
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -494,10 +494,7 @@ namespace CppSharp.Generators.CSharp @@ -494,10 +494,7 @@ namespace CppSharp.Generators.CSharp
{
switch (primitive)
{
case PrimitiveType.Bool:
// returned structs must be blittable and bool isn't
return MarshalKind == MarshalKind.NativeField ?
"byte" : "bool";
case PrimitiveType.Bool: return "bool";
case PrimitiveType.Void: return "void";
case PrimitiveType.Char16:
case PrimitiveType.Char32:

Loading…
Cancel
Save