Browse Source

Fixed #638 - incompilable generated C# code when a function takes a protected enum.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/642/head
Dimitar Dobrev 9 years ago
parent
commit
38f1707474
  1. 6
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 3
      tests/Common/Common.Tests.cs
  3. 8
      tests/Common/Common.cpp
  4. 19
      tests/Common/Common.h

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

@ -2885,7 +2885,11 @@ namespace CppSharp.Generators.CSharp
if (@enum.IsFlags) if (@enum.IsFlags)
WriteLine("[Flags]"); 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, var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type,
new TypeQualifiers()); new TypeQualifiers());

3
tests/Common/Common.Tests.cs

@ -25,6 +25,9 @@ public class CommonTests : GeneratorTestFixture
using (var derivedFromTemplateInstantiationWithVirtual = new DerivedFromTemplateInstantiationWithVirtual()) using (var derivedFromTemplateInstantiationWithVirtual = new DerivedFromTemplateInstantiationWithVirtual())
{ {
} }
using (var hasProtectedEnum = new HasProtectedEnum())
{
}
} }
[Test] [Test]

8
tests/Common/Common.cpp

@ -610,3 +610,11 @@ NonTrivialDtor::~NonTrivialDtor()
DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual() DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual()
{ {
} }
HasProtectedEnum::HasProtectedEnum()
{
}
void HasProtectedEnum::function(ProtectedEnum param)
{
}

19
tests/Common/Common.h

@ -1072,10 +1072,25 @@ public:
DerivedFromTemplateInstantiationWithVirtual(); DerivedFromTemplateInstantiationWithVirtual();
}; };
typedef DLL_API union { typedef DLL_API union
{
int c; int c;
} union_t; } union_t;
int DLL_API func_union(union_t u) { int DLL_API func_union(union_t u)
{
return u.c; return u.c;
} }
class DLL_API HasProtectedEnum
{
public:
HasProtectedEnum();
protected:
enum class ProtectedEnum
{
Member1,
Member2
};
void function(ProtectedEnum param);
};

Loading…
Cancel
Save