Browse Source

Fixed the generated C# when a method with a default arg is named the same as another, non-default, of its parameters.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
7c9c91acc3
  1. 6
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 1
      tests/CSharp/CSharp.Tests.cs
  3. 5
      tests/CSharp/CSharp.cpp
  4. 1
      tests/CSharp/CSharp.h

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

@ -2399,16 +2399,16 @@ namespace CppSharp.Generators.CSharp @@ -2399,16 +2399,16 @@ namespace CppSharp.Generators.CSharp
}
}
GenerateManagedCall(function);
GenerateManagedCall(function, prependThis: function.Parameters.Any(p => !p.Ignore && p.Name == function.Name));
}
private void GenerateManagedCall(Function function, bool prependBase = false)
private void GenerateManagedCall(Function function, bool prependBase = false, bool prependThis = false)
{
var type = function.OriginalReturnType.Type;
var index = 0;
WriteLine("{0}{1}{2}({3});",
type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ",
prependBase ? "base." : string.Empty,
prependBase ? "base." : prependThis ? "this." : string.Empty,
function.Name,
string.Join(", ",
function.Parameters.Where(

1
tests/CSharp/CSharp.Tests.cs

@ -229,6 +229,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -229,6 +229,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithCharFromInt();
methodsWithDefaultValues.DefaultWithFreeConstantInNameSpace();
methodsWithDefaultValues.DefaultWithStdNumericLimits(10, 5);
methodsWithDefaultValues.DefaultWithParamNamedSameAsMethod(5);
}
}

5
tests/CSharp/CSharp.cpp

@ -636,6 +636,11 @@ void MethodsWithDefaultValues::defaultWithStdNumericLimits(double d, int i) @@ -636,6 +636,11 @@ void MethodsWithDefaultValues::defaultWithStdNumericLimits(double d, int i)
{
}
int MethodsWithDefaultValues::DefaultWithParamNamedSameAsMethod(int DefaultWithParamNamedSameAsMethod, const Foo& defaultArg)
{
return 1;
}
int MethodsWithDefaultValues::getA()
{
return m_foo.A;

1
tests/CSharp/CSharp.h

@ -429,6 +429,7 @@ public: @@ -429,6 +429,7 @@ public:
void defaultWithCharFromInt(char c = 32);
void defaultWithFreeConstantInNameSpace(int c = HasFreeConstant::FREE_CONSTANT_IN_NAMESPACE);
void defaultWithStdNumericLimits(double d = 1.0, int i = std::numeric_limits<double>::infinity());
int DefaultWithParamNamedSameAsMethod(int DefaultWithParamNamedSameAsMethod, const Foo& defaultArg = Foo());
int getA();
private:
Foo m_foo;

Loading…
Cancel
Save