1

We are sending a 64-bit enum from our C# back-end to our clients browsers via Web API 2. One of the requirements for the application is that it should run on Windows 10 x64 with ie11. However when I start ie11 I get two processes, one 64-bit and one 32-bit by default. Will a 64-bit enum work with ie11 or not? We do not wan't to go with the enum option if it can't handle more than 32 flags.

enter image description here

We are using TypeScript to handle flags and compiling it to ES5 with Webpack.

What are enum Flags in TypeScript?

We use TypeLITE to generate TypeScript definitions.

http://type.litesolutions.net/

C# model:

[Flags]
[TsEnum(Module = "Application")]
public enum ValidationErrorType : Int64
{
    None = 0,
    NoCaseForRenewalCycle = 1 << 0, // 1
    RegistrationNumberExists = 1 << 1, // 2
    ApplicationNumberMissing = 1 << 2, // 4
    FeeCalculationNoPrice = 1 << 3, // 8
    //...
}

TypeLite.Net4, Enums.ts:

namespace Application {
    export const enum ValidationErrorType {
        None = 0,
        NoCaseForRenewalCycle = 1,
        RegistrationNumberExists = 2,
        ApplicationNumberMissing = 4,
        FeeCalculationNoPrice = 8
    }
}
Ogglas
  • 62,132
  • 37
  • 328
  • 418

1 Answers1

1

Browser process bitness doesn't matter here at all. But what matters is javascript doesn't have such thing as 64-bit integer. Javascript has number type, which is basically C# double. For that reason, javascript cannot safely represent integers bigger than 2^53-1 (Number.MAX_SAFE_INTEGER constant). Also all bit operators (<<, | etc) work with numbers as 32-bit integers, which also doesn't help this situation. For example, 1 << 32 evaluates to 1 in javascript.

So your 64-bit typescript enum is a minefield which will lead to potentially hard to detect bugs, and for that reason I'd avoid it.

If you cannot avoid it - you have to use some library which is able to work with 64-bit numbers, such as BigJS (but then I suppose you cannot use typescript enum).

Evk
  • 98,527
  • 8
  • 141
  • 191