You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
5 years ago
|
#if FAT
|
||
|
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Globalization;
|
||
|
using System.Reflection;
|
||
|
|
||
|
namespace LinqInternal.Collections.Specialized
|
||
|
{
|
||
|
internal sealed class EnumCollection<TEnum> : ProgressiveCollection<TEnum>
|
||
|
{
|
||
|
private static readonly EnumCollection<TEnum> _instance = new EnumCollection<TEnum>();
|
||
|
|
||
|
private EnumCollection()
|
||
|
: base(GetEnumerable())
|
||
|
{
|
||
|
//Empty
|
||
|
}
|
||
|
|
||
|
public static EnumCollection<TEnum> Instance
|
||
|
{
|
||
|
get { return _instance; }
|
||
|
}
|
||
|
|
||
|
public static IEnumerable<TEnum> GetEnumerable()
|
||
|
{
|
||
|
var type = CheckType();
|
||
|
foreach (var item in Enum.GetValues(type))
|
||
|
{
|
||
|
yield return (TEnum)item;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static string ToString(TEnum value)
|
||
|
{
|
||
|
var type = CheckType();
|
||
|
return Enum.GetName(type, value);
|
||
|
}
|
||
|
|
||
|
private static Type CheckType()
|
||
|
{
|
||
|
var type = typeof(TEnum);
|
||
|
var info = type.GetTypeInfo();
|
||
|
if (info.IsEnum)
|
||
|
{
|
||
|
return type;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} is not an Enum", type.Name));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|