Browse Source

Fixed the generated C# for indexers with dependent keys.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1033/head
Dimitar Dobrev 8 years ago
parent
commit
a1327b4402
  1. 14
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 1
      tests/CSharp/CSharpTemplates.h

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

@ -556,11 +556,12 @@ namespace CppSharp.Generators.CSharp
realPointer = templateSubstitution.Replacement.Type.Desugar() as PointerType; realPointer = templateSubstitution.Replacement.Type.Desugar() as PointerType;
realPointer = realPointer ?? pointer; realPointer = realPointer ?? pointer;
var pointee = pointer.Pointee.Desugar(); var pointee = pointer.Pointee.Desugar();
if (Context.Function != null && realPointer.IsPrimitiveTypeConvertibleToRef() && if (Context.Function != null &&
Context.MarshalKind != MarshalKind.VTableReturnValue && (realPointer.IsPrimitiveTypeConvertibleToRef() ||
Context.Function.OperatorKind != CXXOperatorKind.Subscript) (templateSubstitution != null && realPointer.Pointee.IsEnumType())) &&
Context.MarshalKind != MarshalKind.VTableReturnValue)
{ {
var refParamPtr = string.Format("__refParamPtr{0}", Context.ParameterIndex); var refParamPtr = $"__refParamPtr{Context.ParameterIndex}";
if (templateSubstitution != null) if (templateSubstitution != null)
{ {
var castParam = $"__{Context.Parameter.Name}{Context.ParameterIndex}"; var castParam = $"__{Context.Parameter.Name}{Context.ParameterIndex}";
@ -573,8 +574,9 @@ namespace CppSharp.Generators.CSharp
Context.Before.Write("&"); Context.Before.Write("&");
Context.Before.WriteLine($"{castParam};"); Context.Before.WriteLine($"{castParam};");
Context.Return.Write(refParamPtr); Context.Return.Write(refParamPtr);
return true;
} }
else if (Context.Function.OperatorKind != CXXOperatorKind.Subscript)
{ {
if (Context.Parameter.Kind == ParameterKind.PropertyValue) if (Context.Parameter.Kind == ParameterKind.PropertyValue)
{ {
@ -588,8 +590,8 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteStartBraceIndent(); Context.Before.WriteStartBraceIndent();
Context.Return.Write(refParamPtr); Context.Return.Write(refParamPtr);
} }
return true;
} }
return true;
} }
var param = Context.Parameter; var param = Context.Parameter;

1
tests/CSharp/CSharpTemplates.h

@ -346,6 +346,7 @@ class TemplateWithIndexer
public: public:
TemplateWithIndexer(); TemplateWithIndexer();
T& operator[](int i); T& operator[](int i);
T& operator[](const T& key);
T& operator[](const char* string); T& operator[](const char* string);
private: private:
T t[1]; T t[1];

Loading…
Cancel
Save