EnumHelper.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SCC.Models;
  6. namespace SCC.Common
  7. {
  8. /// <summary>
  9. /// 枚举帮助类
  10. /// </summary>
  11. public static class EnumHelper
  12. {
  13. /// <summary>
  14. /// 获取彩种对应数据库表名称
  15. /// </summary>
  16. /// <param name="value">彩种枚举类型</param>
  17. /// <returns></returns>
  18. public static string GetSCCLotteryTableName(Enum value)
  19. {
  20. if (value == null)
  21. {
  22. throw new ArgumentException("value");
  23. }
  24. string TableName = value.ToString();
  25. var fieldInfo = value.GetType().GetField(TableName);
  26. var attributes = (TableNameAttribute[])fieldInfo.GetCustomAttributes(typeof(TableNameAttribute), false);
  27. if (attributes != null && attributes.Length > 0)
  28. {
  29. TableName = attributes[0].TableName;
  30. }
  31. return TableName;
  32. }
  33. }
  34. }