using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace WorkFlowCheck.Common.Helper
{
    public static class DisplayNameHelper
    {
        public static string GetDisplayName(string propertyName, Type modelType)
        {
            var property = modelType.GetProperty(propertyName);
            var displayNameAttribute = property?.GetCustomAttributes(typeof(DisplayNameAttribute), false)
                                           .FirstOrDefault() as DisplayNameAttribute;

            return displayNameAttribute?.DisplayName ?? propertyName;
        }
        public static string GetEnumDisplayName(this Enum enumValue)
        {
            return enumValue
                .GetType()
                .GetMember(enumValue.ToString())
                .First()
                .GetCustomAttribute<DisplayAttribute>()?
                .Name ?? enumValue.ToString();
        }
    }

}
