增强.Net语言以支持ENUM定义中的继承 [英] Enhancing .Net Languages to support inheritance in ENUM definitions

查看:64
本文介绍了增强.Net语言以支持ENUM定义中的继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为.Net语言的ENUM定义提供对继承的支持?作为一个简单的示例,请考虑以下c#声明…

Would it be possible to provide support for inheritance in ENUM definitions for .Net languages? As a simple example, consider the following c# declarations…

没有继承的当前声明
---------------------------------------

Current declaration without inheritance
---------------------------------------

公共枚举UpdatePhoneErrorResults
{
    OK = 0,
   失败,
   无法连接,
    InvalidUsernameOrPassword,
    NoDataReturned,
    InvalidNumber
}

public enum UpdatePhoneErrorResults
{
    Ok = 0,
    Failed,
    UnableToConnect,
    InvalidUsernameOrPassword,
    NoDataReturned,
    InvalidNumber
}

公共枚举UpdateEmailErrorResults
{
    OK = 0,
   失败,
   无法连接,
    InvalidUsernameOrPassword,
    NoDataReturned,
    InvalidEmail
}

public enum UpdateEmailErrorResults
{
    Ok = 0,
    Failed,
    UnableToConnect,
    InvalidUsernameOrPassword,
    NoDataReturned,
    InvalidEmail
}

使用继承的建议声明
--------------------------------------

Proposed declaration using inheritance
--------------------------------------

公共枚举ErrorResults
{
    OK = 0,
   失败
}

public enum ErrorResults
{
    Ok = 0,
    Failed
}

公共枚举DatabaseErrorResults:ErrorResults
{
   无法连接,
    InvalidUsernameOrPassword,
    NoDataReturned
}

public enum DatabaseErrorResults : ErrorResults
{
    UnableToConnect,
    InvalidUsernameOrPassword,
    NoDataReturned
}

公共枚举UpdatePhoneErrorResults:DatabaseErrorResults
{
    InvalidNumber
}

public enum UpdatePhoneErrorResults : DatabaseErrorResults
{
    InvalidNumber
}

公共枚举UpdateEmailErrorResults:DatabaseErrorResults
{
    InvalidEmail
}

public enum UpdateEmailErrorResults : DatabaseErrorResults
{
    InvalidEmail
}

即使通过这个简单的示例,也可以看到能够继承ENUM定义作为获得一致的错误处理和定义的一种方式的好处.这将允许用户开发其软件的不同部分或层,以保持一致 期望.同样,只要通过添加另一个条目来更新父ENUM,则该ENUM定义和每个继承的ENUM定义也将接收新条目.如果用户必须像现在一样维护分开的ENUM定义,则不能 确保所有其他预期的ENUM定义都得到更新.例如,如果您要向数据库错误结果ENUM中添加一个名为TimedOut的新条目,如上所示,则两个最终的ENUM定义都将自动接收新定义的条目 如果允许继承.否则,用户可能会忘记更新UpdatePhoneErrorResults或UpdateEmailErrorResults或两者都没有继承.

Even with this simple example, one can see the benefits of being able to inherit ENUM definitions as a way to get consistent error handling and definitions. This would allow users to develop different parts or layers of their software that maintains consistent expectations. Also, whenever a parent ENUM is updated by adding another entry, both that ENUM definition an each inherited ENUM definition receive the new entry as well. If the user had to maintain to separate ENUM definitions as they do now, they can’t be guaranteed that ALL other intended ENUM definitions get updated. For example, if you were to add a new entry named TimedOut to the DatabaseErrorResults ENUM as show above, both of the final ENUM definitions would automatically receive the newly defined entry if inheritance is allowed. Otherwise the user might forget to update either the UpdatePhoneErrorResults or UpdateEmailErrorResults or both without inheritance.

推荐答案

Hi

Hi Doug Putz,

我建议您将用户语音提交到 在这里.让我们知道您希望在将来的MS产品版本中看到什么.该站点提供建议和想法.如果您需要提交错误,可以访问我们的 开发者社区网站以开始使用.

I would suggest you submit your User Voice to HERE. Let us know what you would like to see in future versions of MS products. This site is for suggestions and ideas. If you need to file a bug, you can visit our Developer Community website to get started. 

最诚挚的问候,

克里斯汀


这篇关于增强.Net语言以支持ENUM定义中的继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆