Permalink
Browse files

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

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 28, 2017
1 parent db164c0 commit f9a8798b8fd7e7013db28bebbb76d18ec3418ca5
@@ -28,7 +28,8 @@ public enum ParameterKind
IndirectReturnType,
OperatorParameter,
ImplicitDestructorParameter,
Extension
Extension,
PropertyValue
}
public class Parameter : Declaration, ITypedDecl
@@ -507,11 +507,18 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
}
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;
}
@@ -795,7 +795,8 @@ private void GenerateFunctionSetter(Class @class, Property property)
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())
@@ -45,7 +45,7 @@ public void TestCodeGeneration()
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 @@ public void TestVirtualFunctionWithBoolParams()
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));
}
}
}
@@ -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)
{
}
double TestProperties::refToPrimitiveInSetter() const
{
return _refToPrimitiveInSetter;
}
void TestProperties::setRefToPrimitiveInSetter(const double& value)
{
_refToPrimitiveInSetter = value;
}
HasOverridenSetter::HasOverridenSetter()
{
}
@@ -582,8 +582,12 @@ struct DLL_API TestProperties
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

0 comments on commit f9a8798

Please sign in to comment.