bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.63k stars 104 forks source link

enum and flag --no-reflection #169

Closed LaszloLueck closed 7 months ago

LaszloLueck commented 7 months ago

For space reasons, I use bflat with the --no-reflection flag for a build (stdlib: dotnet). If I use this flag, no more enums are resolved.

For example:

enum YesNo
    {
        Yes = 1,
        No = 2,
        NotSure = 3   
    }

In my Main():

var xyz = YesNo.Yes;
Console.WriteLine(xyz);

If I compile this with --no-reflection, I get back 1 as output. If I leave out the --no-reflection flag, I get Yes as output.

Is this the normal behaviour or have I overlooked something?

Regards!

MichalStrehovsky commented 7 months ago

Yes, this is expected. Enum stringification is done by reflecting over the fields of the enum type. It's reflection like any other.

LaszloLueck commented 7 months ago

Thanks for clarification. I have now solved this with enumeration classes.

Regards!