【问题标题】:64-bit enum flag in Internet Explorer 11Internet Explorer 11 中的 64 位枚举标志
【发布时间】:2018-04-23 22:38:48
【问题描述】:

我们正在通过 Web API 2 从 C# 后端向我们的客户端浏览器发送一个 64 位枚举。应用程序的要求之一是它应该在 Windows 10 x64 with ie11 上运行。但是,当我启动ie11 时,我会得到两个进程,一个是 64 位的,一个是 32 位的。 64 位枚举是否可以与 ie11 一起使用?如果 enum 选项不能处理超过 32 个标志,我们不想使用它。

我们使用TypeScript 来处理标志并使用 Webpack 将其编译为 ES5。

What are enum Flags in TypeScript?

我们使用 TypeLITE 来生成 TypeScript 定义。

http://type.litesolutions.net/

C#模型:

[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
    }
}

【问题讨论】:

  • 你能显示你的 64 位枚举的定义吗?
  • @Evk 更新了模型

标签: javascript c# typescript internet-explorer internet-explorer-11


【解决方案1】:

浏览器进程位数在这里根本不重要。但重要的是 javascript 没有 64 位整数之类的东西。 Javascript有number类型,基本上是C#double。因此,javascript 不能安全地表示大于 2^53-1(Number.MAX_SAFE_INTEGER 常量)的整数。此外,所有位运算符(&lt;&lt;| 等)都将数字作为 32 位整数使用,这也无助于这种情况。例如,1 &lt;&lt; 32 在 javascript 中的计算结果为 1

所以你的 64 位 typescript 枚举是一个雷区,可能会导致难以检测的错误,因此我会避免它。

如果你无法避免 - 你必须使用一些能够处理 64 位数字的库,例如 BigJS(但我想你不能使用 typescript enum)。

【讨论】:

    猜你喜欢
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    • 2014-05-08
    • 1970-01-01
    相关资源
    最近更新 更多