From 22bd02c8497cb97e0f35bfd43303b7bec441c0b3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Dec 2016 22:44:13 +0200 Subject: [PATCH] Revert "Shortened the generated C# code for patching v-tables." This reverts commit 2486d1d419141c11317f5675f9b78e224beff428. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpSources.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 1ac93648..620be3de 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -1448,14 +1448,18 @@ namespace CppSharp.Generators.CSharp WriteStartBraceIndent(); WriteLine("_Thunks = new void*[{0}];", wrappedEntries.Count); + var uniqueEntries = new HashSet(); + for (int i = 0; i < wrappedEntries.Count; i++) { var entry = wrappedEntries[i]; var method = entry.Method; var name = GetVTableMethodDelegateName(method); - WriteLine($@"_Thunks[{i}] = Marshal.GetFunctionPointerForDelegate(new { - GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace) - }({name}Hook)).ToPointer();"); + var instance = name + "Instance"; + if (uniqueEntries.Add(entry)) + WriteLine("{0} += {1}Hook;", instance, name); + WriteLine("_Thunks[{0}] = Marshal.GetFunctionPointerForDelegate({1}).ToPointer();", + i, instance); } WriteCloseBraceIndent(); @@ -1723,6 +1727,11 @@ namespace CppSharp.Generators.CSharp var vTableMethodDelegateName = GetVTableMethodDelegateName(method); + WriteLine("private static {0} {1}Instance;", + GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace), + vTableMethodDelegateName); + NewLine(); + WriteLine("private static {0} {1}Hook({2})", retType, vTableMethodDelegateName, string.Join(", ", @params)); WriteStartBraceIndent();