From a1559de421cfa945373047c34037068b6a78bd67 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Thu, 11 Apr 2019 01:11:58 +0300 Subject: [PATCH] Add a generic pointer to resolve ambiguity Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTypePrinter.cs | 10 +++++++--- src/Runtime/Pointer.cs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/Runtime/Pointer.cs diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 050f0af190..8dc19a0df5 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -561,9 +561,13 @@ public TypePrinterResult VisitTemplateArgument(TemplateArgument a) if (a.Type.Type == null) return a.Integral.ToString(CultureInfo.InvariantCulture); var type = a.Type.Type.Desugar(); - return type.IsPointerToPrimitiveType() && !type.IsConstCharString() ? - IntPtrType : type.IsPrimitiveType(PrimitiveType.Void) ? "object" : - type.Visit(this).Type; + PrimitiveType pointee; + if (type.IsPointerToPrimitiveType(out pointee) && !type.IsConstCharString()) + { + return $@"CppSharp.Runtime.Pointer<{(pointee == PrimitiveType.Void ? IntPtrType : + VisitPrimitiveType(pointee, new TypeQualifiers()).Type)}>"; + } + return (type.IsPrimitiveType(PrimitiveType.Void)) ? "object" : type.Visit(this).Type; } public override TypePrinterResult VisitParameterDecl(Parameter parameter) diff --git a/src/Runtime/Pointer.cs b/src/Runtime/Pointer.cs new file mode 100644 index 0000000000..2afed52771 --- /dev/null +++ b/src/Runtime/Pointer.cs @@ -0,0 +1,13 @@ +using System; + +namespace CppSharp.Runtime +{ + public class Pointer + { + public Pointer(IntPtr ptr) => this.ptr = ptr; + + public static implicit operator IntPtr(Pointer pointer) => pointer.ptr; + + private readonly IntPtr ptr; + } +}