From 47633db649889f9a88a9c0008e658cc3a8e1f1a4 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 5 Aug 2017 16:16:53 +0300 Subject: [PATCH] Moved the handling of indexers to the C# marshaller. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 4 ++++ src/Generator/Generators/CSharp/CSharpSources.cs | 12 +++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index ab3bc281..643bc367 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -169,6 +169,10 @@ namespace CppSharp.Generators.CSharp if (Context.Context.Options.MarshalCharAsManagedChar && primitive == PrimitiveType.Char) Context.Return.Write(string.Format("({0}) ", pointer)); + if (Context.Function != null && + Context.Function.OperatorKind == CXXOperatorKind.Subscript && + Context.ReturnType.Type.Desugar().IsPrimitiveType(primitive)) + Context.Return.Write("*"); Context.Return.Write(Context.ReturnVarName); return true; } diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 6d252bbd..30d16536 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2754,7 +2754,8 @@ namespace CppSharp.Generators.CSharp ArgName = Helpers.ReturnIdentifier, ReturnVarName = Helpers.ReturnIdentifier, ReturnType = returnType, - Parameter = operatorParam + Parameter = operatorParam, + Function = function }; var marshal = new CSharpMarshalNativeToManagedPrinter(ctx); @@ -2766,14 +2767,7 @@ namespace CppSharp.Generators.CSharp if (ctx.HasCodeBlock) PushIndent(); - // Special case for indexer - needs to dereference if the internal - // function is a pointer type and the property is not. - if (retType.Type.IsAddress() && - retType.Type.GetPointee().Equals(returnType.Type) && - returnType.Type.IsPrimitiveType()) - WriteLine("return *{0};", marshal.Context.Return); - else - WriteLine("return {0};", marshal.Context.Return); + WriteLine($"return {marshal.Context.Return};"); if (ctx.HasCodeBlock) WriteCloseBraceIndent();