gpt4 book ai didi

.net - 应对落后的枚举支持

转载 作者:行者123 更新时间:2023-12-05 01:28:36 26 4
gpt4 key购买 nike

在 EF 5.0(计划很快发布)之前, Entity Framework 将不支持枚举。

Entity Framework 4.2 enum support

http://blogs.msdn.com/b/efdesign/archive/2011/06/29/enumeration-support-in-entity-framework.aspx

http://visualstudiomagazine.com/blogs/data-driver/2012/01/entity-framework-4-3-gets-final-tune-up.aspx

WCF 数据服务(和 oData 标准)不支持枚举

We understand that enums are common, unfortunately they never met tha bar so far. They are rather high on our list of things to do next though

(参见:https://stackoverflow.com/a/3571378/141172)

我开始了一个新项目,正在用类似的东西替换枚举:

public static class MyEnum
{
public const int MyValue = 0;
public const int AnotherValue = 1;
}

我牺牲了枚举提供的保证,即只有定义的值才会被分配,以便利用重要的(并且在这一点上相当成熟的)基础设施服务。

是否有更好的方法来处理滞后的枚举支持?一旦 EF 和 WCF 数据服务添加了枚举支持,是否可能会出现另一个重要的框架,它会像这两个框架一样缓慢地引入枚举支持?

最佳答案

你能否使用一个带有私有(private)构造函数的结构,为每个值定义一个公共(public)静态成员:

public struct FakeEnum
{
public static readonly FakeEnum MyValue = new FakeEnum(0);
public static readonly FakeEnum AnotherValue = new FakeEnum(1);

private readonly int _value;

private FakeEnum(int value)
{
_value = value;
}

public int Value { get { return _value; } }

// TODO: Equals and GetHasCode and Operators Oh My!
}

注意:我还没有实际尝试过。

关于.net - 应对落后的枚举支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9185116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com