Browse Source

Fixed the allocation of internal abstract implementations, and fixed their constructors to take a pointer to the abstract type.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/53/head
Dimitar Dobrev 12 years ago
parent
commit
da6887ff07
  1. 2
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 18
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -216,7 +216,7 @@ namespace CppSharp.Generators.CSharp
instance = copy; instance = copy;
} }
if (@class.IsRefType) if (@class.IsRefType && !@class.IsAbstract)
{ {
var instanceName = Generator.GeneratedIdentifier("instance"); var instanceName = Generator.GeneratedIdentifier("instance");
if (VarSuffix > 0) if (VarSuffix > 0)

18
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1359,23 +1359,31 @@ namespace CppSharp.Generators.CSharp
private void GenerateNativeConstructor(Class @class) private void GenerateNativeConstructor(Class @class)
{ {
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}({1}.Internal* native)", SafeIdentifier(@class.Name), string className = @class.Name;
@class.Name); string safeIdentifier = SafeIdentifier(className);
if (@class.Access == AccessSpecifier.Private &&
className.EndsWith("Internal"))
{
className = className.Substring(0,
safeIdentifier.LastIndexOf("Internal", StringComparison.Ordinal));
}
WriteLine("internal {0}({1}.Internal* native)", safeIdentifier,
className);
WriteLineIndent(": this(new global::System.IntPtr(native))"); WriteLineIndent(": this(new global::System.IntPtr(native))");
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}({1}.Internal native)", SafeIdentifier(@class.Name), WriteLine("internal {0}({1}.Internal native)", safeIdentifier,
@class.Name); className);
WriteLineIndent(": this(&native)"); WriteLineIndent(": this(&native)");
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}(global::System.IntPtr native){1}", SafeIdentifier(@class.Name), WriteLine("internal {0}(global::System.IntPtr native){1}", safeIdentifier,
@class.IsValueType ? " : this()" : string.Empty); @class.IsValueType ? " : this()" : string.Empty);
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType; var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;

Loading…
Cancel
Save