在C#中如何实现枚举类型的特性扩展和反射获取
来源:互联网 发布:sql给表增加字段 编辑:程序博客网 时间:2024/06/05 20:47
public enum 月定制项目
{
[CustomItemAttribute()]
一点五元夜餐次数=1,
[CustomItemAttribute()]
二元夜餐次数=2,
[CustomItemAttribute()]
连班次数 =3,
[CustomItemAttribute()]
甲类保健津贴次数 =4,
[CustomItemAttribute()]
乙类保健津贴次数 =5,
[CustomItemAttribute()]
周六加班次数 =6,
[CustomItemAttribute()]
周日加班次数 =7,
[CustomItemAttribute()]
零点夜班次数 =8,
[CustomItemAttribute()]
节假日加班次数 =9,
[CustomItemAttribute()]
四点夜班次数 =10,
[CustomItemAttribute()]
事假天数=11,
[CustomItemAttribute()]
病假天数 =12,
[CustomItemAttribute()]
旷工天数 =13,
[CustomItemAttribute()]
公差天数 =14,
[CustomItemAttribute()]
探亲天数 =15,
[CustomItemAttribute(CustomApplyType.工区员工)]
效益工资 = 16
}
public enum CustomApplyType
{
工区员工 = 1,
机关员工 = 2,
所有员工 = 3
}
[AttributeUsage(AttributeTargets.Field)]
public class CustomItemAttribute:System.Attribute
{
protected CustomApplyType _customApplyType;
public CustomItemAttribute(CustomApplyType customApplyType)
{
this._customApplyType = customApplyType;
}
public CustomItemAttribute():this(CustomApplyType.所有员工)
{
}
public CustomApplyType CustomApplyType{get{return this._customApplyType;}}
}
class Application
{
[STAThread]
static void Main(string[] args)
{
FieldInfo[] fs = typeof(月定制项目).GetFields();
object enumInstance = typeof(月定制项目).Assembly.CreateInstance(typeof(月定制项目).FullName);
foreach(FieldInfo f in fs)
{
CustomItemAttribute[] cas = (CustomItemAttribute[])f.GetCustomAttributes(typeof(CustomItemAttribute),true);
if(cas.Length >0)
{
Console.WriteLine(f.GetValue(enumInstance));
Console.WriteLine(Convert.ToSingle((int)f.GetValue(enumInstance)));
Console.WriteLine(cas[0].CustomApplyType.ToString());
}
}
Console.Read();
}
}
- 在C#中如何实现枚举类型的特性扩展和反射获取
- 自定义枚举以及如何在反射中获取枚举值
- 使用反射来获取枚举的名称、值和特性
- C# 枚举类型的扩展
- C# 中反射获取某类的子类和根据类型名动态创建对象(转载)
- c#枚举类型的内容全部获取和字符串转换为枚举类型的方法
- C#反射 与 枚举类型
- C#中的特性 和 通过反射获取属性上的特性
- C#中动态扩展一个新类型的实现
- 如何在C#语言中实现int类型的数字以字符类型输出
- C#反射和特性
- c# 反射和特性
- C# 特性和反射
- C#特性和反射
- c#反射机制学习和利用反射获取类型信息
- C#中如何获取字体类型,颜色,和大小.
- C#反射和特性的应用
- C#反射的特性
- theprogresscreateandmodifyDatabase
- 取网页中的IP发送Email
- 使用Lomboz3生成Struts2项目后运行Tomcat出现Unable to load bean错误的解决
- C#泛型学习笔记之一(约束)
- 手工修改spfile文件后,产生ora-00600错误解决方法
- 在C#中如何实现枚举类型的特性扩展和反射获取
- 获取进程命令行之四
- 一位高手悟出的炒股铁律,照着做,富可敌国!
- 无题
- 又见QQ十大最牛签名
- Mysql 常见问题
- 希望百度伺机再猛炒一番珊瑚虫,推出传闻已久的百度小声
- 关于敏捷团队建设的一点想法
- 带条件的添加语句(insert +where 条件)