Пример #1
0
        public IColumnBuilder <TItem> Add(Expression <Func <TItem, object> > expression)
        {
            var memberAccessor = new MemberAccessor <TItem>(expression);
            var column         = new ColumnBuilder <TItem>(this, memberAccessor);

            _columns.Add(column);

            return(column);
        }
Пример #2
0
        private void GenerateColumns()
        {
            var memberInfos =
                typeof(TItem).GetMembers(BindingFlags.Public | BindingFlags.Instance)
                .Where(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property);
            var members = new List <Member>();

            foreach (var memberInfo in memberInfos)
            {
                var columnFormat = memberInfo
                                   .GetCustomAttributes(true)
                                   .SingleOrDefault(x => x is ColumnAttribute) as ColumnAttribute;
                if (columnFormat is null)
                {
                    members.Add(new Member {
                        Index = 0, MemberInfo = memberInfo, ColumnAttribute = null
                    });
                }

                if (columnFormat != null)
                {
                    members.Add(new Member {
                        Index = columnFormat.Index, MemberInfo = memberInfo, ColumnAttribute = columnFormat
                    });
                }
            }

            foreach (var member in members.OrderBy(x => x.Index))
            {
                var memberAccessor = new MemberAccessor <TItem>(member.MemberInfo);
                var column         = new ColumnBuilder <TItem>(this, memberAccessor);
                _columns.Add(column);

                if (member.ColumnAttribute == null)
                {
                    continue;
                }

                if (member.ColumnAttribute.Header != null)
                {
                    column.NameAs(member.ColumnAttribute.Header);
                }

                column
                .HorizontalAlignmentAs(member.ColumnAttribute.HorizontalAlignment)
                .VerticalAlignmentAs(member.ColumnAttribute.VerticalAlignment)
                .FormatAs(member.ColumnAttribute.Format);
            }
        }