Browse Source

Add the GenerateSequentialLayout option

Signed-off-by: Alin Gherman <Alin Gherman>
pull/770/head
Alin Gherman 9 years ago
parent
commit
6e42ef36a6
  1. 20
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 1
      src/Generator/Options.cs

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

@ -561,8 +561,15 @@ namespace CppSharp.Generators.CSharp @@ -561,8 +561,15 @@ namespace CppSharp.Generators.CSharp
public void GenerateClassInternals(Class @class)
{
PushBlock(CSharpBlockKind.InternalsClass);
WriteLine("[StructLayout(LayoutKind.Explicit, Size = {0})]",
@class.Layout.Size);
if (Options.GenerateSequentialLayout)
{
WriteLine("[StructLayout(LayoutKind.Sequential)]");
}
else
{
WriteLine("[StructLayout(LayoutKind.Explicit, Size = {0})]",
@class.Layout.Size);
}
GenerateClassInternalHead(@class);
WriteStartBraceIndent();
@ -772,7 +779,14 @@ namespace CppSharp.Generators.CSharp @@ -772,7 +779,14 @@ namespace CppSharp.Generators.CSharp
PushBlock(CSharpBlockKind.Field);
WriteLine("[FieldOffset({0})]", field.Offset);
if (Options.GenerateSequentialLayout)
{
// For the sequential layout there is no need to set an offset
}
else
{
WriteLine("[FieldOffset({0})]", field.Offset);
}
TypePrinter.PushMarshalKind(MarshalKind.NativeField);
var fieldTypePrinted = field.QualifiedType.CSharpType(TypePrinter);

1
src/Generator/Options.cs

@ -161,6 +161,7 @@ namespace CppSharp @@ -161,6 +161,7 @@ namespace CppSharp
public bool OutputInteropIncludes;
public bool GenerateFunctionTemplates;
public bool GenerateInternalImports;
public bool GenerateSequentialLayout;
public bool UseHeaderDirectories;
/// <summary>

Loading…
Cancel
Save