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 @@ -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());

3
tests/Common/Common.Tests.cs

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

8
tests/Common/Common.cpp

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

19
tests/Common/Common.h

@ -1072,10 +1072,25 @@ public: @@ -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);
};

Loading…
Cancel
Save