how can i expose description attribute in enum values from service to client or web reference using WCF or
how can i expose enum with description attribute to client
you can do this using reflection. back in the client after you have the Enum value.. try picking up the attribute using GetField() & GetCustomAttributes()
using System;
using System.Reflection;
using System.ComponentModel;
namespace CustomAttributes
{
class Program
{
static void Main(string[] args)
{
Colors n1 = Colors.blue;
object [] attribues = n1.GetType().GetField(n1.ToString()).GetCustomAttributes(true);
Console.WriteLine((attribues[0] as DescriptionAttribute).Description);
// WOULD PRINT "DARK BLUE"
}
}
enum Colors
{
[Description("DARK BLUE")]
blue,
[Description("PLAIN WHITE")]
white
}
}