易截截图软件、单文件、免安装、纯绿色、仅160KB

c# enmu 枚举小结(2)自己的

通过反射,得到针对某一枚举类型的描述。
枚举的定义中加入描述
  using System;
using System.Collections;
namespace Ahnlab.ApplicationServices
{
public sealed partial class SysEnums
{


#region 系统管理模块的枚举信息
/// <summary>
/// 在线不良赔偿协议书状态
/// </summary>
public enum YesNo
{
[TextAttribute("是")]
Yes = 0,
[TextAttribute("否")]
No = 1
}
/// <summary>
/// 用户类型
/// </summary>
public enum UserType
{
[TextAttribute("公司员工")]
Employee = 1,
[TextAttribute("代理商")]
Agent = 2,
[TextAttribute("供应商")]
Vendor = 3,
[TextAttribute("系统管理员")]
Admin = 4
}
/// <summary>
/// 密码重置标记
/// </summary>
public enum PasswordResetEnum
{
[TextAttribute("是")]
Yes = 1,
[TextAttribute("否")]
No = 0
}
#endregion
}

/// <summary>
/// 构造枚举类
/// add by kenny
/// add date
/// </summary>
public class TextAttribute : Attribute
{
public string Text
{
get
{
return _Text;
}
set
{
_Text = value;
}
}
string _Text;
public TextAttribute(string text)
{
_Text = text;
}
}
 
获得值 Type enumType = typeof(SysEnums.UserType);//枚举属性
int enumConst = int.Parse(UserType.ToString());//枚举对应的值
string textVal = "";
string strValue = string.Empty;
Type typeDescription = typeof(Ahnlab.ApplicationServices.TextAttribute);
FieldInfo fi


相关文档:

C#中ref参数与out参数的区别

先贴代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ref_and_Out_test
{
    class Program
    {
        static void Main(string[] args)
      & ......

C#中String.Empty与""

    这两个在一般情况下是相等的,但是系统处理机制上却有所不同。
    ""会在内存里划一块长度为0的存储空间,而String.Empty内存并不为它分配空间,所以无论性能还是速度上String.Empty都优于""。
    曾经看过一篇判断字符串空值的性能文章,老外写的国人翻译,文章大意 ......

C#事件(event)解析

      事件(event),这个词儿对于初学者来说,往往总是显得有些神秘,不易弄懂。而这些东西却往往又是编程中常用且非常重要的东西。大家都知道windows消息处理机制的重要,其实C#事件就是基于windows消息处理机制的,只是封装的更好,让开发者无须知道底层的消息处理机制,就可以开发出强大的基于 ......

c# enmu 枚举小结(1)

 
枚举
  枚举类型声明为一组相关的符号常数定义了一个类型名称。枚举用于“多项选择”场合,就是程序运行时从编译时已经设定的固定数目的“选择”中做出决定。
  枚举类型(也称为枚举)为定义一组可以赋给变量的命名整数常量提供了一种有效的方法。例如,假设您必须定义一个变量,该变量 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号