123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models.Entity.LottomatBaseDB;
- using Models.Entity.LotteryNumDB;
- using Models;
- using System.Reflection;
- namespace Common
- {
- /// <summary>
- /// 枚举帮助类
- /// </summary>
- public static class EnumHelper
- {
- /// <summary>
- /// 获取彩种对应数据库表名称
- /// </summary>
- /// <param name="value">彩种枚举类型</param>
- /// <returns></returns>
- public static string GetSCCLotteryTableName(Enum value)
- {
- if (value == null)
- {
- throw new ArgumentException("value");
- }
- string TableName = value.ToString();
- var fieldInfo = value.GetType().GetField(TableName);
- var attributes = (TableNameAttribute[])fieldInfo.GetCustomAttributes(typeof(TableNameAttribute), false);
- if (attributes != null && attributes.Length > 0)
- {
- TableName = attributes[0].TableName;
- }
- return TableName;
- }
- /// <summary>
- /// 获取彩种对应TDK标签
- ///
- /// </summary>
- /// <param name="value">彩种枚举类型</param>
- /// <returns></returns>
- public static string GetSCCLotteryTDKTypeName(Enum value)
- {
- if (value == null)
- {
- throw new ArgumentException("value");
- }
- string TableName = value.ToString();
- var fieldInfo = value.GetType().GetField(TableName);
- var attributes = (TDKTypeAttribute[])fieldInfo.GetCustomAttributes(typeof(TDKTypeAttribute), false);
- if (attributes != null && attributes.Length > 0)
- {
- TableName = attributes[0].TDKType;
- }
- return TableName;
- }
-
- /// <summary>
- /// 获取彩种对应编码
- /// </summary>
- /// <param name="value">彩种枚举类型</param>
- /// <returns></returns>
- public static string GetLotteryCode(Enum value)
- {
- if (value == null)
- {
- throw new ArgumentException("value");
- }
- string code = value.ToString();
- var fieldInfo = value.GetType().GetField(code);
- var attributes = (LotteryCodeAttribute[])fieldInfo.GetCustomAttributes(typeof(LotteryCodeAttribute), false);
- if (attributes != null && attributes.Length > 0)
- {
- code = attributes[0].Code;
- }
- return code;
- }
- /// <summary>
- /// 获取彩种对应编码
- /// </summary>
- /// <param name="value">彩种枚举类型</param>
- /// <returns></returns>
- public static string GetLotteryText(Enum value)
- {
- if (value == null)
- {
- throw new ArgumentException("value");
- }
- string code = value.ToString();
- var fieldInfo = value.GetType().GetField(code);
- var attributes = (TextAttribute[])fieldInfo.GetCustomAttributes(typeof(TextAttribute), false);
- if (attributes != null && attributes.Length > 0)
- {
- code = attributes[0].Text;
- }
- return code;
- }
- /// <summary>
- /// 获取咨询数据库的表名
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetZXTableName<T>()
- {
- var type = typeof(T)
- ; var attribute = type.GetCustomAttributes(typeof(ZXTableNameAttribute), false).FirstOrDefault();
- if (attribute == null)
- {
- return null;
- }
- return ((ZXTableNameAttribute)attribute).TableName;
-
- }
- /// <summary>
- /// 获取备注信息对应的枚举值
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public static string GETEnumTypeByText<T>( string text)
- {
- Type type = typeof(T);
- FieldInfo[] fds = type.GetFields();
- foreach (var fd in fds)
- {
- object[] attrs = fd.GetCustomAttributes(typeof(TextAttribute), false);
- foreach (TextAttribute attr in attrs)
- {
- var name = attr.Text;
- if (name == text)
- return fd.Name;
- }
- }
- return null;
- }
- }
- }
|