The following provides a helper to provide Enum.GetNames functionality for .NET Compact Framework 3.5 using LINQ and Reflection:
using System
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace MyApp.Helpers
{
public static class EnumHelper
{
public static string[] GetNames(Type enumType)
{
FieldInfo[] fieldInfo = enumType.GetFields(BindingFlags.Static BindingFlags.Public);
returnfieldInfo.Select(f => f.Name).ToArray();
}
}
}
The enum we will use for the example:
namespace MyAPP
{
public enum DeliveryMethod { SMS = 0, Service, Email };
}
Usage:
public void Test()
{
foreach ( string name in EnumHelper.GetNames( typeof (DeliveryMethod)))
{
MessageBox.Show(name);
}
}
