using System.Reflection;

namespace OrderEntrySystem
{
    public static class DisplayUtil
    {
        public static string GetControlDescription(MemberInfo memberInfo)
        {
            string result = ReflectionUtil.GetAttributePropertyValueAsString(memberInfo, typeof(EntityControlAttribute), "Description");

            if (result == null || result == string.Empty)
            {
                result = memberInfo.Name.ToString();
            }

            return result;
        }

        public static ControlType GetControlType(PropertyInfo propertyInfo)
        {
            object result = ReflectionUtil.GetAttributePropertyValue(propertyInfo, typeof(EntityControlAttribute), "ControlType");

            if (result == null)
            {
                result = ControlType.None;
            }

            return (ControlType)result;
        }

        public static bool HasControl(MemberInfo memberInfo)
        {
            return ReflectionUtil.HasAttribute(memberInfo, typeof(EntityControlAttribute));
        }
    }
}
