diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index f2d11426..85b6a254 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -728,14 +728,6 @@ namespace CppSharp.Generators.CSharp private void MarshalRefClass(Class @class) { var method = Context.Function as Method; - if (method != null - && method.Conversion == MethodConversionKind.FunctionToInstanceMethod - && Context.ParameterIndex == 0) - { - Context.Return.Write("{0}", Helpers.InstanceIdentifier); - return; - } - string param = Context.Parameter.Name; Type type = Context.Parameter.Type.Desugar(resolveTemplateSubstitution: false); string paramInstance; diff --git a/tests/CSharp/CSharp.Gen.cs b/tests/CSharp/CSharp.Gen.cs index 25d4205b..3e48a759 100644 --- a/tests/CSharp/CSharp.Gen.cs +++ b/tests/CSharp/CSharp.Gen.cs @@ -31,6 +31,10 @@ namespace CppSharp.Tests public override void SetupPasses(Driver driver) { driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass()); + var moveFunctionToClassPass = driver.Context.TranslationUnitPasses.FindPass(); + driver.Context.TranslationUnitPasses.RemovePass(moveFunctionToClassPass); + driver.Context.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass()); + driver.Context.TranslationUnitPasses.AddPass(new MoveFunctionToClassPass()); driver.Options.MarshalCharAsManagedChar = true; driver.Options.GenerateDefaultValuesForArguments = true; driver.Options.GenerateClassTemplates = true; diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 646bcd50..aa7a0532 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -1894,6 +1894,13 @@ public unsafe class CSharpTests Assert.That(CSharp.CSharp.TestFunctionToStaticMethodConstRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6)); } + [Test] + public void TestFunctionToInstanceMethod() + { + Assert.That(new TestClass().FunctionToInstanceMethod(5), Is.EqualTo(25)); + Assert.That(new TestClass().FunctionToInstanceMethod(new FTIStruct() { A = 5 }), Is.EqualTo(25)); + } + [TestCase(typeof(FTIStruct), ExpectedResult = true)] [TestCase(typeof(ClassWithoutNativeToManaged), ExpectedResult = false)] public bool TestClassGenerateNativeToManaged(Type type) diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index ea58d12d..8cb552ae 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -1692,6 +1692,9 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue) { return defaultValue.a; } DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue) { return defaultValue.a; } +DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value) { return value * value; } +DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& value) { return value.a * value.a; } + int RuleOfThreeTester::constructorCalls = 0; int RuleOfThreeTester::destructorCalls = 0; int RuleOfThreeTester::copyConstructorCalls = 0; diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index ccae3928..bc959388 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -1535,6 +1535,11 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue); DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue); +class DLL_API TestClass { int a; }; + +DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value); +DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& cc); + class ClassWithoutNativeToManaged { }; struct DLL_API ClassWithIntValue {