Browse Source

Simplified the printing of pointers in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1089/head
Dimitar Dobrev 7 years ago
parent
commit
634892ebe7
  1. 18
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

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

@ -185,13 +185,8 @@ namespace CppSharp.Generators.CSharp
if (MarshalKind == MarshalKind.NativeField) if (MarshalKind == MarshalKind.NativeField)
return IntPtrType; return IntPtrType;
var pointee = pointer.Pointee; if (pointer.Pointee is FunctionType)
return pointer.Pointee.Visit(this, quals);
if (pointee is FunctionType)
{
var function = pointee as FunctionType;
return string.Format("{0}", function.Visit(this, quals));
}
var isManagedContext = ContextKind == TypePrinterContextKind.Managed; var isManagedContext = ContextKind == TypePrinterContextKind.Managed;
@ -206,11 +201,10 @@ namespace CppSharp.Generators.CSharp
if (Options.Encoding == Encoding.Unicode || if (Options.Encoding == Encoding.Unicode ||
Options.Encoding == Encoding.BigEndianUnicode) Options.Encoding == Encoding.BigEndianUnicode)
return string.Format("[MarshalAs(UnmanagedType.LPWStr)] string"); return string.Format("[MarshalAs(UnmanagedType.LPWStr)] string");
throw new NotSupportedException(string.Format("{0} is not supported yet.", throw new NotSupportedException($"{Options.Encoding.EncodingName} is not supported yet.");
Options.Encoding.EncodingName));
} }
var desugared = pointee.Desugar(); var pointee = pointer.Pointee.Desugar();
// From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
// Any of the following types may be a pointer type: // Any of the following types may be a pointer type:
@ -243,7 +237,7 @@ namespace CppSharp.Generators.CSharp
} }
Enumeration @enum; Enumeration @enum;
if (desugared.TryGetEnum(out @enum)) if (pointee.TryGetEnum(out @enum))
{ {
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
if (isManagedContext && Parameter != null && (Parameter.IsOut || Parameter.IsInOut) if (isManagedContext && Parameter != null && (Parameter.IsOut || Parameter.IsInOut)
@ -254,7 +248,7 @@ namespace CppSharp.Generators.CSharp
} }
Class @class; Class @class;
if ((desugared.IsDependent || desugared.TryGetClass(out @class)) if ((pointee.IsDependent || pointee.TryGetClass(out @class))
&& ContextKind == TypePrinterContextKind.Native) && ContextKind == TypePrinterContextKind.Native)
{ {
return IntPtrType; return IntPtrType;

Loading…
Cancel
Save