Получите Список доступных Перечислений

Попробуйте без даты ()

SELECT * FROM StockHandler.product 
WHERE date(stock_timestamp) BETWEEN  '2019-03-03' AND '2019-03-04' 
ORDER BY quantity DESC  LIMIT 3 
5
задан Community 23 May 2017 в 12:04
поделиться

3 ответа

Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>();
14
ответ дан 18 December 2019 в 08:31
поделиться

I agree with @mquander's code.

However, I would suggest you also cache the list, since it's extremely unlikely to change over the course of the execution of your program. Put it in a static readonly variable in some global location:

public static class MyGlobals
{
   public static readonly List<MyEnum> EnumList = 
       Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>().ToList();
}
3
ответ дан 18 December 2019 в 08:31
поделиться

Not a one liner (well the implementation isn't, but the method is :P), but perhaps add something like this to a tools/ utility class which will return a generic list:

public static List<T> EnumToList<T>()

{

 Type enumType = typeof(T);

 // Can't use type constraints on value types, so have to do check like this

 if (enumType.BaseType != typeof(Enum))

  throw new ArgumentException("T must be of type System.Enum");

 return new List<T>(Enum.GetValues(enumType) as IEnumerable<T>);

}
2
ответ дан 18 December 2019 в 08:31
поделиться
Другие вопросы по тегам:

Похожие вопросы: