상속: System.Attribute
예제 #1
0
        private String GetValue(Object model, String fullPropertyName)
        {
            if (model == null)
            {
                return("");
            }

            Type type = model.GetType();

            String[]     properties = fullPropertyName.Split('.');
            PropertyInfo property   = type.GetProperty(properties[0]);

            if (property == null)
            {
                throw new DatalistException(String.Format("'{0}' type does not have property named '{1}'.", type.Name, properties[0]));
            }

            if (properties.Length > 1)
            {
                return(GetValue(property.GetValue(model), String.Join(".", properties.Skip(1))));
            }

            Object value = property.GetValue(model) ?? "";
            DatalistColumnAttribute column = property.GetCustomAttribute <DatalistColumnAttribute>(false);

            if (column != null && column.Format != null)
            {
                value = String.Format(column.Format, value);
            }

            return(value.ToString());
        }
예제 #2
0
        protected virtual String GetColumnKey(PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

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

            if (column != null && column.Relation != null)
            {
                return(property.Name + "." + GetColumnKey(GetRelationProperty(property, column.Relation)));
            }

            return(property.Name);
        }
예제 #3
0
        protected MvcDatalist()
        {
            Id           = (model) => GetValue(model, "Id");
            Autocomplete = (model) => GetValue(model, Columns.Where(col => !col.Hidden).Select(col => col.Key).FirstOrDefault() ?? "");

            foreach (PropertyInfo property in AttributedProperties)
            {
                DatalistColumnAttribute column = property.GetCustomAttribute <DatalistColumnAttribute>(false);
                Columns.Add(new DatalistColumn(GetColumnKey(property), GetColumnHeader(property))
                {
                    CssClass   = GetColumnCssClass(property),
                    Filterable = column.Filterable,
                    Hidden     = column.Hidden
                });
            }
        }
예제 #4
0
        private String GetValue(T model, String propertyName)
        {
            PropertyInfo property = typeof(T).GetProperty(propertyName);

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

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

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

            return(property.GetValue(model)?.ToString());
        }
예제 #5
0
        protected virtual String GetColumnHeader(PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

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

            if (column != null && column.Relation != null)
            {
                return(GetColumnHeader(GetRelationProperty(property, column.Relation)));
            }

            DisplayAttribute header = property.GetCustomAttribute <DisplayAttribute>(false);

            if (header != null)
            {
                return(header.GetName());
            }
            return(property.Name);
        }