protected virtual OLVColumn MakeColumnFromAttribute(PropertyInfo pinfo, OLVColumnAttribute attr) { return MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), pinfo.CanWrite, pinfo.PropertyType, attr); }
/// <summary> /// Generate a list of OLVColumns based on the attributes of the given type /// that have a OLVColumn attribute. /// </summary> /// <param name="type"></param> /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns> static public IList <OLVColumn> GenerateColumns(Type type) { List <OLVColumn> columns = new List <OLVColumn>(); // Iterate all public properties in the class and build columns from those that have // an OLVColumn attribute. foreach (PropertyInfo pinfo in type.GetProperties()) { OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; if (attr != null) { columns.Add(Generator.MakeColumnFromAttribute(pinfo.Name, attr, pinfo.CanWrite)); } } // How many columns have DisplayIndex specifically set? int countPositiveDisplayIndex = 0; foreach (OLVColumn col in columns) { if (col.DisplayIndex >= 0) { countPositiveDisplayIndex += 1; } } // Give columns that don't have a DisplayIndex an incremental index int columnIndex = countPositiveDisplayIndex; foreach (OLVColumn col in columns) { if (col.DisplayIndex < 0) { col.DisplayIndex = (columnIndex++); } } columns.Sort(delegate(OLVColumn x, OLVColumn y) { return(x.DisplayIndex.CompareTo(y.DisplayIndex)); }); return(columns); }