Browse Source

Fixed the wrapping of indexers returning value types.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/256/merge
Dimitar Dobrev 10 years ago
parent
commit
1c52e67bb8
  1. 12
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 11
      tests/Common/Common.h

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

@ -933,9 +933,15 @@ namespace CppSharp.Generators.CSharp @@ -933,9 +933,15 @@ namespace CppSharp.Generators.CSharp
}
else
{
WriteLine("*({0}.Internal*) Internal.{1}({2}, {3}) = *({0}.Internal*) value.{4};",
type.ToString(), internalFunction, GetInstanceParam(function),
function.Parameters[0].Name, Helpers.InstanceIdentifier);
var typeString = type.ToString();
Class @class;
var isValueType = (type.GetFinalPointee() ?? type).TryGetClass(out @class) &&
@class.IsValueType;
WriteLine("*({0}.Internal*) Internal.{1}({2}, {3}) = {4}value.{5};",
typeString, internalFunction, GetInstanceParam(function),
function.Parameters[0].Name,
isValueType ? string.Empty : string.Format("*({0}.Internal*) ", typeString),
Helpers.InstanceIdentifier);
}
}

11
tests/Common/Common.h

@ -527,8 +527,6 @@ void TestProperties::setFieldValue(int Value) { Field = Value; } @@ -527,8 +527,6 @@ void TestProperties::setFieldValue(int Value) { Field = Value; }
class DLL_API TestIndexedProperties
{
foo_t p;
TestProperties f;
public:
TestIndexedProperties();
// Should lead to a read/write indexer with return type uint
@ -545,6 +543,11 @@ public: @@ -545,6 +543,11 @@ public:
const TestProperties& operator[](short b);
// Should lead to a read-only indexer with argument type TestProperties
foo_t operator[](TestProperties b);
Bar& operator[](unsigned long i);
private:
foo_t p;
TestProperties f;
Bar bar;
};
TestIndexedProperties::TestIndexedProperties() : p(1), f() {}
@ -555,6 +558,10 @@ const foo_t& TestIndexedProperties::operator[](double f) { return p; } @@ -555,6 +558,10 @@ const foo_t& TestIndexedProperties::operator[](double f) { return p; }
TestProperties* TestIndexedProperties::operator[](unsigned char b) { return &f; }
const TestProperties& TestIndexedProperties::operator[](short b) { return f; }
foo_t TestIndexedProperties::operator[](TestProperties b) { return p; }
Bar& TestIndexedProperties::operator[](unsigned long i)
{
return bar;
}
struct DLL_API TestIndexedPropertiesInValueType
{

Loading…
Cancel
Save