From 38f17074741c24d799be9704db2a587d06e8b917 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 29 Mar 2016 01:16:07 +0300 Subject: [PATCH] Fixed #638 - incompilable generated C# code when a function takes a protected enum. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 6 +++++- tests/Common/Common.Tests.cs | 3 +++ tests/Common/Common.cpp | 8 ++++++++ tests/Common/Common.h | 19 +++++++++++++++++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index d27e6b74..6b663836 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2885,7 +2885,11 @@ namespace CppSharp.Generators.CSharp if (@enum.IsFlags) WriteLine("[Flags]"); - Write("{0}enum {1}", Helpers.GetAccess(@enum.Access), @enum.Name); + Write(Helpers.GetAccess(@enum.Access)); + // internal P/Invoke declarations must see protected enums + if (@enum.Access == AccessSpecifier.Protected) + Write("internal "); + Write("enum {0}", @enum.Name); var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type, new TypeQualifiers()); diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 24223db2..88c12b07 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -25,6 +25,9 @@ public class CommonTests : GeneratorTestFixture using (var derivedFromTemplateInstantiationWithVirtual = new DerivedFromTemplateInstantiationWithVirtual()) { } + using (var hasProtectedEnum = new HasProtectedEnum()) + { + } } [Test] diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 40f3c626..6248d528 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -610,3 +610,11 @@ NonTrivialDtor::~NonTrivialDtor() DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual() { } + +HasProtectedEnum::HasProtectedEnum() +{ +} + +void HasProtectedEnum::function(ProtectedEnum param) +{ +} diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 910f6286..50eb04ce 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -1072,10 +1072,25 @@ public: DerivedFromTemplateInstantiationWithVirtual(); }; -typedef DLL_API union { +typedef DLL_API union +{ int c; } union_t; -int DLL_API func_union(union_t u) { +int DLL_API func_union(union_t u) +{ return u.c; } + +class DLL_API HasProtectedEnum +{ +public: + HasProtectedEnum(); +protected: + enum class ProtectedEnum + { + Member1, + Member2 + }; + void function(ProtectedEnum param); +};