From da6887ff073f0d34a99859df9d119a6a8c2a3d68 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 9 Sep 2013 14:56:10 +0300 Subject: [PATCH] Fixed the allocation of internal abstract implementations, and fixed their constructors to take a pointer to the abstract type. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpMarshal.cs | 2 +- .../Generators/CSharp/CSharpTextTemplate.cs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 115feb18..49a3ef71 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -216,7 +216,7 @@ namespace CppSharp.Generators.CSharp instance = copy; } - if (@class.IsRefType) + if (@class.IsRefType && !@class.IsAbstract) { var instanceName = Generator.GeneratedIdentifier("instance"); if (VarSuffix > 0) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index abd433fa..d63d77cf 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1359,23 +1359,31 @@ namespace CppSharp.Generators.CSharp private void GenerateNativeConstructor(Class @class) { PushBlock(CSharpBlockKind.Method); - WriteLine("internal {0}({1}.Internal* native)", SafeIdentifier(@class.Name), - @class.Name); + string className = @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))"); WriteStartBraceIndent(); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); PushBlock(CSharpBlockKind.Method); - WriteLine("internal {0}({1}.Internal native)", SafeIdentifier(@class.Name), - @class.Name); + WriteLine("internal {0}({1}.Internal native)", safeIdentifier, + className); WriteLineIndent(": this(&native)"); WriteStartBraceIndent(); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); 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); var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;