【问题标题】:extending enum property from referenced dll [duplicate]从引用的dll扩展枚举属性[重复]
【发布时间】:2014-11-18 20:42:51
【问题描述】:

在mvc4里面我有模型

public class MyViewModel
{
    public SomeEnum MyEnum { get; set; }
    public string Name { get; set; }
}

这个 SomeEnum 位于从我的网络应用程序引用的其他 dll 中。我无法更改此 dll (SomeEnum),但为了更清楚起见,我想使用此枚举 (SomeEnum),但扩展很少,我想添加更多枚举属性。

如何做到这一点?

【问题讨论】:

  • 你可以看到你需要的一切here

标签: c# .net asp.net-mvc


【解决方案1】:

基本上不能。

你所能做的就是声明一个新的枚举,可能在不同的命名空间中使用相同的名称,也可能使用不同的名称:

namespace My.Local {
    public enum SomeEnum {
        // the originals
        A = The.Other.SomeEnum.A,
        B = The.Other.SomeEnum.B,
        C = The.Other.SomeEnum.C,
        // the extras
        D, E, F
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多