为啥这么常用的方法在Silverlight里居然没有呢?自己写一个:
using
System;
using System.Linq;
namespace SampleApp
{
public class EnumHelper
{
public static T[] GetValues < T > ()
{
Type type = typeof (T);
if ( ! type.IsEnum)
{
throw new InvalidOperationException( " Type parameter T should be an enum " );
}
var fields = type.GetFields().Where(fi => fi.IsLiteral);
return fields.Select(fi => (T)fi.GetValue(type)).ToArray();
}
}
}
using System.Linq;
namespace SampleApp
{
public class EnumHelper
{
public static T[] GetValues < T > ()
{
Type type = typeof (T);
if ( ! type.IsEnum)
{
throw new InvalidOperationException( " Type parameter T should be an enum " );
}
var fields = type.GetFields().Where(fi => fi.IsLiteral);
return fields.Select(fi => (T)fi.GetValue(type)).ToArray();
}
}
}