コード例 #1
0
        /// <summary>
        /// Generate a list of OLVColumns based on the attributes of the given type
        /// If allProperties to true, all public properties will have a matching column generated.
        /// If allProperties is false, only properties that have a OLVColumn attribute will have a column generated.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="allProperties">Will columns be generated for properties that are not marked with [OLVColumn].</param>
        /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns>
        public override IList <OLVColumn> GenerateColumns(Type type, bool allProperties)
        {
            List <OLVColumn> columns = new List <OLVColumn>();

            // Sanity
            if (type == null)
            {
                return(columns);
            }

            PropertyInfo[] pList = AttrHelper.GetBasePropertiesFirst(type);
            PropertyInfo   pName = AttrHelper.GetProperty <JNameProperty>(type);

            if (pName != null)
            {
                pList = pList.OrderBy(x => x != pName).ToArray();
            }

            // Iterate all public properties in the class and build columns from those that have
            // an OLVColumn attribute and that are not ignored.
            //foreach (PropertyInfo pinfo in type.GetProperties())
            foreach (PropertyInfo pinfo in pList)
            {
                if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null)
                {
                    continue;
                }
                //added j
                if (Attribute.GetCustomAttribute(pinfo, typeof(JIgnore)) != null)
                {
                    continue;
                }
                //if (Attribute.GetCustomAttribute(pinfo, typeof(JManyToOne)) != null)
                //  continue; //обычно дублирована с JForeinKey поэтому оставляем одну

                OLVColumnAttribute attr   = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute;
                OLVColumn          column = null;
                if (attr == null)
                {
                    if (allProperties)
                    {
                        column = this.MakeColumnFromPropertyInfo(pinfo);
                    }
                }
                else
                {
                    column = this.MakeColumnFromAttribute(pinfo, attr);
                }
                if (column != null)
                {
                    columns.Add(column);
                }
            }

            // 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);
        }
コード例 #2
0
        /// <summary>
        /// Generate a list of OLVColumns based on the attributes of the given type
        /// If allProperties to true, all public properties will have a matching column generated.
        /// If allProperties is false, only properties that have a OLVColumn attribute will have a column generated.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="allProperties">Will columns be generated for properties that are not marked with [OLVColumn].</param>
        /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns>
        public override IList <OLVColumn> GenerateColumns(Type type, bool allProperties)
        {
            List <OLVColumn> columns = new List <OLVColumn>();

            // Sanity
            if (type == null)
            {
                return(columns);
            }

            PropertyInfo[] pList = AttrHelper.GetBasePropertiesFirst(type);
            PropertyInfo   pName = AttrHelper.GetProperty <JNameProperty>(type);

            if (pName != null)
            {
                pList = pList.OrderBy(x => x != pName).ToArray();
            }

            // Iterate all public properties in the class and build columns from those that have
            // an OLVColumn attribute and that are not ignored.
            //foreach (PropertyInfo pinfo in type.GetProperties())
            foreach (PropertyInfo pinfo in pList)
            {
                if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null)
                {
                    continue;
                }
                //added j
                if (Attribute.GetCustomAttribute(pinfo, typeof(JIgnore)) != null)
                {
                    continue;
                }

                OLVColumnAttribute attr   = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute;
                OLVColumn          column = null;
                if (attr == null)
                {
                    if (allProperties)
                    {
                        column = this.MakeColumnFromPropertyInfo(pinfo);
                    }
                }
                else
                {
                    column = this.MakeColumnFromAttribute(pinfo, attr);
                }
                if (column != null)
                {
                    //reset checkboxes (setted by ConfigurePossibleBooleanColumn()) for correct working of virtual lists
                    column.CheckBoxes = false;
                    columns.Add(column);
                }
            }

            // 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);
        }