BrightIdeasSoftware.Generator.MakeColumnFromAttribute C# (CSharp) Метод

MakeColumnFromAttribute() защищенный Метод

Create a column from the given PropertyInfo and OLVColumn attribute
protected MakeColumnFromAttribute ( PropertyInfo pinfo, BrightIdeasSoftware.OLVColumnAttribute attr ) : OLVColumn
pinfo System.Reflection.PropertyInfo
attr BrightIdeasSoftware.OLVColumnAttribute
Результат OLVColumn
        protected virtual OLVColumn MakeColumnFromAttribute(PropertyInfo pinfo, OLVColumnAttribute attr)
        {
            return MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), pinfo.CanWrite, pinfo.PropertyType, attr);
        }

Usage Example

Пример #1
0
        /// <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);
        }
All Usage Examples Of BrightIdeasSoftware.Generator::MakeColumnFromAttribute