Browse Source

Fixed code generation of subscript operator for types with non-default parameter usage.

pull/621/merge
Joao Matos 10 years ago
parent
commit
62d5f00c77
  1. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 8
      tests/Common/Common.h

11
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1216,8 +1216,15 @@ namespace CppSharp.Generators.CSharp @@ -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)

8
tests/Common/Common.h

@ -556,6 +556,9 @@ public: @@ -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) @@ -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
{

Loading…
Cancel
Save