﻿namespace Scheduler.HealthCheck.Wpf.Extensions
{
    using System;
    using System.ComponentModel.DataAnnotations;

    public static class EnumExtensions
    {
        public static string DisplayName(this Enum value)
        {
            if (value == null)
            {
                return string.Empty;
            }

            var element = (DisplayAttribute[])(value.GetType()
                                                    .GetField(value.ToString()))
                                                                                .GetCustomAttributes(typeof(DisplayAttribute), false);

            return element.Length > 0 ? element[0].Name : string.Empty;
        }
    }
}