Generate FlagsAttribute for Csharp (#5370)

For schema enums with the bit_flags attribute, generate the
corresponding System.FlagsAttribute in generated Csharp code.
This commit is contained in:
Marc Butler
2019-05-31 08:57:41 +10:00
committed by Wouter van Oortmerssen
parent 43dbac5d25
commit 93f74c0363
2 changed files with 6 additions and 0 deletions

View File

@@ -510,6 +510,11 @@ class GeneralGenerator : public BaseGenerator {
std::string &code = *code_ptr; std::string &code = *code_ptr;
if (enum_def.generated) return; if (enum_def.generated) return;
// In C# this indicates enumeration values can be treated as bit flags.
if (lang_.language == IDLOptions::kCSharp && enum_def.attributes.Lookup("bit_flags")) {
code += "[System.FlagsAttribute]\n";
}
// Generate enum definitions of the form: // Generate enum definitions of the form:
// public static (final) int name = value; // public static (final) int name = value;
// In Java, we use ints rather than the Enum feature, because we want them // In Java, we use ints rather than the Enum feature, because we want them

View File

@@ -5,6 +5,7 @@
namespace MyGame.Example namespace MyGame.Example
{ {
[System.FlagsAttribute]
public enum Color : byte public enum Color : byte
{ {
Red = 1, Red = 1,