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 9 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
IndirectReturnType, IndirectReturnType,
OperatorParameter, OperatorParameter,
ImplicitDestructorParameter, ImplicitDestructorParameter,
Extension Extension,
PropertyValue
} }
public class Parameter : Declaration, ITypedDecl public class Parameter : Declaration, ITypedDecl

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

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

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

@ -795,7 +795,8 @@ namespace CppSharp.Generators.CSharp
var param = new Parameter var param = new Parameter
{ {
Name = "value", 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()) if (!property.Type.Equals(param.Type) && property.Type.IsEnumType())

13
tests/Common/Common.Tests.cs

@ -45,7 +45,7 @@ public class CommonTests : GeneratorTestFixture
e = EnumWithUnderscores.UsesDigits1_0; e = EnumWithUnderscores.UsesDigits1_0;
e.GetHashCode(); e.GetHashCode();
Common.SMallFollowedByCapital(); Common.SMallFollowedByCapital();
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) {} using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { }
#pragma warning restore 0168 #pragma warning restore 0168
#pragma warning restore 0219 #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
using (var hasVirtualFunctionWithBoolParam = new HasVirtualFunctionWithBoolParams()) using (var hasVirtualFunctionWithBoolParam = new HasVirtualFunctionWithBoolParams())
Assert.That(hasVirtualFunctionWithBoolParam.VirtualFunctionWithBoolParamAndReturnsBool(true)); 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()
return s; return s;
} }
TestProperties::TestProperties() : Field(0) TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0)
{ {
} }
@ -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() HasOverridenSetter::HasOverridenSetter()
{ {
} }

4
tests/Common/Common.h

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

Loading…
Cancel
Save