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
} }
} }
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 type = function.OriginalReturnType.Type;
var index = 0; var index = 0;
WriteLine("{0}{1}{2}({3});", WriteLine("{0}{1}{2}({3});",
type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ", type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ",
prependBase ? "base." : string.Empty, prependBase ? "base." : prependThis ? "this." : string.Empty,
function.Name, function.Name,
string.Join(", ", string.Join(", ",
function.Parameters.Where( function.Parameters.Where(

1
tests/CSharp/CSharp.Tests.cs

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

5
tests/CSharp/CSharp.cpp

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

1
tests/CSharp/CSharp.h

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

Loading…
Cancel
Save