Example #1
0
 public static FormatCategory FormatToCategory(ItemFormat format)
 {
     lock (_dictFormatToCategory) {
         if (_dictFormatToCategory.Count == 0)
         {
             List <FieldInfo> listFields = typeof(ItemFormat).GetFields().ToList();
             foreach (ItemFormat f in EnumUtils.GetAll <ItemFormat>())
             {
                 FieldInfo           field = listFields.FirstOrDefault(x => x.Name == f.ToString());
                 ItemFormatAttribute attr  = field?.GetCustomAttribute <ItemFormatAttribute>();
                 _dictFormatToCategory[f] = attr?.ListCategories?.FirstOrDefault() ?? FormatCategory.Unknown;
             }
         }
         _dictFormatToCategory.TryGetValue(format, out FormatCategory cate);
         return(cate);
     }
 }
Example #2
0
 public static string FormatToDisplay(ItemFormat format)
 {
     lock (_dictFormatToDisplay) {
         if (_dictFormatToDisplay.Count == 0)
         {
             List <FieldInfo> listFields = typeof(ItemFormat).GetFields().ToList();
             foreach (ItemFormat f in EnumUtils.GetAll <ItemFormat>())
             {
                 FieldInfo           field = listFields.FirstOrDefault(x => x.Name == f.ToString());
                 ItemFormatAttribute attr  = field?.GetCustomAttribute <ItemFormatAttribute>();
                 _dictFormatToDisplay[f] = string.IsNullOrWhiteSpace(attr?.FormatDisplay) ? "Other" : attr.FormatDisplay;
             }
         }
         _dictFormatToDisplay.TryGetValue(format, out string display);
         return(display ?? "");
     }
 }