From 62d5f00c77ec2dded7127bc170ea4a4a59abfff0 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Sun, 28 Feb 2016 23:55:52 +0000 Subject: [PATCH] Fixed code generation of subscript operator for types with non-default parameter usage. --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 11 +++++++++-- tests/Common/Common.h | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index a2230d19..a76aa0bb 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1216,8 +1216,15 @@ namespace CppSharp.Generators.CSharp private string GetPropertyName(Property prop) { - return prop.Parameters.Count == 0 ? prop.Name - : string.Format("this[{0}]", FormatMethodParameters(prop.Parameters)); + var isIndexer = prop.Parameters.Count != 0; + var @params = prop.Parameters.Select(param => { + var p = new Parameter(param); + if (isIndexer) + p.Usage = ParameterUsage.In; + return p; + }); + return !isIndexer ? prop.Name + : string.Format("this[{0}]", FormatMethodParameters(@params)); } private void GenerateVariable(Class @class, Type type, Variable variable) diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 9452a922..a68a718b 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -556,6 +556,9 @@ public: foo_t operator[](TestProperties b); Bar& operator[](unsigned long i); Bar& operator[](const TypeMappedIndex& key); + // Test that we do not generate 'ref int' parameters as C# does not allow it + int operator[](CS_OUT char key); + private: foo_t p; TestProperties f; @@ -578,6 +581,11 @@ Bar& TestIndexedProperties::operator[](const TypeMappedIndex& key) { return bar; } +int TestIndexedProperties::operator[](CS_OUT char key) +{ + return key; +} + struct DLL_API TestIndexedPropertiesInValueType {