Browse Source

Fixed the generated C# for setters with a reference to a primitive type.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/906/head
Dimitar Dobrev 8 years ago
parent
commit
f9a8798b8f
  1. 3
      src/AST/Function.cs
  2. 17
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 3
      src/Generator/Generators/CSharp/CSharpSources.cs
  4. 13
      tests/Common/Common.Tests.cs
  5. 12
      tests/Common/Common.cpp
  6. 4
      tests/Common/Common.h

3
src/AST/Function.cs

@ -28,7 +28,8 @@ namespace CppSharp.AST @@ -28,7 +28,8 @@ namespace CppSharp.AST
IndirectReturnType,
OperatorParameter,
ImplicitDestructorParameter,
Extension
Extension,
PropertyValue
}
public class Parameter : Declaration, ITypedDecl

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

@ -507,11 +507,18 @@ namespace CppSharp.Generators.CSharp @@ -507,11 +507,18 @@ namespace CppSharp.Generators.CSharp
}
else
{
Context.Before.WriteLine(
$"fixed ({pointer} {refParamPtr} = &{Context.Parameter.Name})");
Context.HasCodeBlock = true;
Context.Before.WriteStartBraceIndent();
Context.Return.Write(refParamPtr);
if (Context.Parameter.Kind == ParameterKind.PropertyValue)
{
Context.Return.Write($"&{Context.Parameter.Name}");
}
else
{
Context.Before.WriteLine(
$"fixed ({pointer} {refParamPtr} = &{Context.Parameter.Name})");
Context.HasCodeBlock = true;
Context.Before.WriteStartBraceIndent();
Context.Return.Write(refParamPtr);
}
}
return true;
}

3
src/Generator/Generators/CSharp/CSharpSources.cs

@ -795,7 +795,8 @@ namespace CppSharp.Generators.CSharp @@ -795,7 +795,8 @@ namespace CppSharp.Generators.CSharp
var param = new Parameter
{
Name = "value",
QualifiedType = property.SetMethod.Parameters[0].QualifiedType
QualifiedType = property.SetMethod.Parameters[0].QualifiedType,
Kind = ParameterKind.PropertyValue
};
if (!property.Type.Equals(param.Type) && property.Type.IsEnumType())

13
tests/Common/Common.Tests.cs

@ -45,7 +45,7 @@ public class CommonTests : GeneratorTestFixture @@ -45,7 +45,7 @@ public class CommonTests : GeneratorTestFixture
e = EnumWithUnderscores.UsesDigits1_0;
e.GetHashCode();
Common.SMallFollowedByCapital();
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) {}
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { }
#pragma warning restore 0168
#pragma warning restore 0219
@ -793,4 +793,15 @@ This is a very long string. This is a very long string. This is a very long stri @@ -793,4 +793,15 @@ This is a very long string. This is a very long string. This is a very long stri
using (var hasVirtualFunctionWithBoolParam = new HasVirtualFunctionWithBoolParams())
Assert.That(hasVirtualFunctionWithBoolParam.VirtualFunctionWithBoolParamAndReturnsBool(true));
}
[Test]
public void TestRefToPrimitiveInSetter()
{
using (var testProperties = new TestProperties())
{
const double value = 5.5;
testProperties.RefToPrimitiveInSetter = value;
Assert.That(testProperties.RefToPrimitiveInSetter, Is.EqualTo(value));
}
}
}

12
tests/Common/Common.cpp

@ -489,7 +489,7 @@ std::string& HasStdString::getStdString() @@ -489,7 +489,7 @@ std::string& HasStdString::getStdString()
return s;
}
TestProperties::TestProperties() : Field(0)
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0)
{
}
@ -512,6 +512,16 @@ void TestProperties::setVirtual(bool value) @@ -512,6 +512,16 @@ void TestProperties::setVirtual(bool value)
{
}
double TestProperties::refToPrimitiveInSetter() const
{
return _refToPrimitiveInSetter;
}
void TestProperties::setRefToPrimitiveInSetter(const double& value)
{
_refToPrimitiveInSetter = value;
}
HasOverridenSetter::HasOverridenSetter()
{
}

4
tests/Common/Common.h

@ -582,8 +582,12 @@ public: @@ -582,8 +582,12 @@ public:
bool isVirtual();
virtual void setVirtual(bool value);
double refToPrimitiveInSetter() const;
void setRefToPrimitiveInSetter(const double& value);
private:
int FieldValue;
double _refToPrimitiveInSetter;
};
class DLL_API HasOverridenSetter : public TestProperties

Loading…
Cancel
Save