BuildFeed/Code/DisplayHelpers.cs
2014-10-28 23:39:18 +00:00

26 lines
681 B
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace BuildFeed
{
public static class DisplayHelpers
{
public static string GetDisplayTextForEnum(object o)
{
var result = null as string;
var display = o.GetType()
.GetMember(o.ToString()).First()
.GetCustomAttributes(false)
.OfType<DisplayAttribute>()
.LastOrDefault();
if (display != null)
{
result = display.GetName();
}
return result ?? o.ToString();
}
}
}