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

1
tests/CSharp/CSharpTemplates.h

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

Loading…
Cancel
Save