diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index d4338e3ad..ddaae8f4e 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -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 diff --git a/tests/MyGame/Example/Color.cs b/tests/MyGame/Example/Color.cs index 654b16315..897ccc122 100644 --- a/tests/MyGame/Example/Color.cs +++ b/tests/MyGame/Example/Color.cs @@ -5,6 +5,7 @@ namespace MyGame.Example { +[System.FlagsAttribute] public enum Color : byte { Red = 1,