forked from BigfootDev/flatbuffers
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:
committed by
Wouter van Oortmerssen
parent
43dbac5d25
commit
93f74c0363
@@ -510,6 +510,11 @@ class GeneralGenerator : public BaseGenerator {
|
||||
std::string &code = *code_ptr;
|
||||
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:
|
||||
// public static (final) int name = value;
|
||||
// In Java, we use ints rather than the Enum feature, because we want them
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
[System.FlagsAttribute]
|
||||
public enum Color : byte
|
||||
{
|
||||
Red = 1,
|
||||
|
||||
Reference in New Issue
Block a user