Exemple #1
0
        //public static long ToInt64(this Enum value)
        //{
        //    return Convert.ToInt64(value);
        //}


        public static string GetDisplayName(this Enum value)
        {
            var field = value.GetType().GetField(value.ToString());

            return(field == null ? null : DisplayNameHelper.GetDisplayNameForProperty(field));

            //var attributes = field.GetCustomAttributes(typeof(DisplayAttribute), true).ToArray();
            //return attributes.Length > 0 ? ((DisplayAttribute)attributes[0]).GetName() : value.ToString();
        }
        public static string GetDisplayName <TModel, TProperty>(this TModel model, Expression <Func <TModel, TProperty> > expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var me = expression.Body as MemberExpression;

            if (me == null)
            {
                throw new ArgumentException("Must be a MemberExpression.", nameof(expression));
            }

            return(DisplayNameHelper.GetDisplayNameForProperty(me.Member));
        }