Пример #1
0
        protected MvcLookup()
        {
            GetId    = (model) => GetValue(model, "Id");
            GetLabel = (model) => GetValue(model, Columns.Where(col => !col.Hidden).Select(col => col.Key).FirstOrDefault() ?? "");

            foreach (PropertyInfo property in AttributedProperties)
            {
                LookupColumnAttribute column = property.GetCustomAttribute <LookupColumnAttribute>(false);
                Columns.Add(new LookupColumn(GetColumnKey(property), GetColumnHeader(property))
                {
                    CssClass   = GetColumnCssClass(property),
                    Filterable = column.Filterable,
                    Hidden     = column.Hidden
                });
            }
        }
Пример #2
0
        private String GetValue(T model, String propertyName)
        {
            PropertyInfo property = typeof(T).GetProperty(propertyName);

            if (property == null)
            {
                return(null);
            }

            LookupColumnAttribute column = property.GetCustomAttribute <LookupColumnAttribute>(false);

            if (column?.Format != null)
            {
                return(String.Format(column.Format, property.GetValue(model)));
            }

            return(property.GetValue(model)?.ToString());
        }