枚举用法简单示例

2014-07-12 11:02:39  访问(2968) 赞(0) 踩(0)



        /// <summary>
        /// 通过枚举返回不同的角色颜色提示(利用VS的智能感知功能,避免人为错别字)
        /// </summary>
        /// <param name="em"></param>
        /// <returns></returns>
        public string GetInfoByEmUserRole(SlowX.WebKnowledge.Enums.UserRole.EmUserRole em)
        {
            switch (em)
            {
                case SlowX.WebKnowledge.Enums.UserRole.EmUserRole.管理员:
                    return "<font color='red'>" + em.ToString() + "</font>";
                case SlowX.WebKnowledge.Enums.UserRole.EmUserRole.总经理:
                    return "<font color='green'>" + em.ToString() + "</font>";
                case SlowX.WebKnowledge.Enums.UserRole.EmUserRole.部门领导:
                case SlowX.WebKnowledge.Enums.UserRole.EmUserRole.普通职员:
                    return "<font color='blue'>" + em.ToString() + "</font>";
                default:
                    throw new Exception
                        (
                            "方法:" + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName 
                            + " " 
                            + System.Reflection.MethodBase.GetCurrentMethod().ToString() 
                            + " 发生异常:枚举" 
                            + em.GetType().FullName + "." + em.ToString() 
                            + "尚未实现。"
                        );
            }
        }

枚举样例
推荐的枚举写法

标签:枚举    枚举应用    例子    代码示例    枚举使用示例 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)