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
{
///
/// 枚举帮助类
///
public static class EnumHelper
{
///
/// 获取彩种对应数据库表名称
///
/// 彩种枚举类型
///
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;
}
///
/// 获取彩种对应TDK标签
///
///
/// 彩种枚举类型
///
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;
}
///
/// 获取彩种对应编码
///
/// 彩种枚举类型
///
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;
}
///
/// 获取彩种对应编码
///
/// 彩种枚举类型
///
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;
}
///
/// 获取咨询数据库的表名
///
///
///
public static string GetZXTableName()
{
var type = typeof(T)
; var attribute = type.GetCustomAttributes(typeof(ZXTableNameAttribute), false).FirstOrDefault();
if (attribute == null)
{
return null;
}
return ((ZXTableNameAttribute)attribute).TableName;
}
///
/// 获取备注信息对应的枚举值
///
///
///
public static string GETEnumTypeByText( 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;
}
}
}