Beispiel #1
0
        public override bool UseWhen()
        {
            // do deep property binding
            if (!(ColumnName.Contains('.')))
            {
                return(false);
            }

            var propertyNames = ColumnName.Split('.');

            if (propertyNames.Count() <= 1)
            {
                throw new Exception(string.Format("Can not find any property represented by deep-binding syntax: \"{0}\"", ColumnName));
            }

            Info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(TargetType, propertyNames[0]);

            var nextColumnName = string.Join(".", propertyNames.Skip(1).ToList());

            deepAction = ColumnActionFactory.GetAction <ICreatorColumnAction>(Info.PropertyType, nextColumnName);

            if (deepAction == null)
            {
                return(false);
            }

            return(deepAction.UseWhen());
        }
Beispiel #2
0
        public override bool UseWhen()
        {
            if (!DeepHelper.IsDeep(ColumnName))
            {
                return(false);
            }

            var columnNameParts = DeepHelper.SplitColumnName(ColumnName);

            if (!UseWhenProperty(columnNameParts.FirstColumn))
            {
                return(false);
            }

            _deepAction = ColumnActionFactory.GetAction <IComparerColumnAction>(
                _info.PropertyType,
                columnNameParts.OtherColumns);

            if (_deepAction == null)
            {
                return(false);
            }

            return(_deepAction.UseWhen());
        }
Beispiel #3
0
        public CreateColumnBuilder <T> AddSymbolic(string columnName, string symbolic)
        {
            var action = ColumnActionFactory.GetAction <ICreatorColumnAction>(typeof(T), symbolic);

            var aOverride = new ColumnToActionContainer <ICreatorColumnAction>();

            aOverride.ColumnName  = columnName;
            aOverride.MatchAction = action;
            columnOverrides.Add(aOverride);

            return(this);
        }
        /// <summary>
        /// Method to match columns in a table to properties in a object
        /// </summary>
        public static IEnumerable <ColumnToActionContainer <T> > GetActionsFromColumns <T>(
            Table table, Type target, IEnumerable <ColumnToActionContainer <T> > overrides)
            where T : IColumnAction
        {
            //setup my return object
            var columnToActions = new List <ColumnToActionContainer <T> >();

            if (overrides != null)
            {
                foreach (var aOverride in overrides)
                {
                    if (aOverride.ColumnIndex == null)
                    {
                        // convert name to index
                        for (int i = 0; i < table.Header.Count; i++)
                        {
                            if (table.Header.ElementAt(i) == aOverride.ColumnName)
                            {
                                aOverride.ColumnIndex = i;
                                columnToActions.Add(aOverride);
                            }
                        }
                        continue;
                    }

                    if (aOverride.ColumnName == null)
                    {
                        aOverride.ColumnName = table.Header.ElementAt(aOverride.ColumnIndex.Value);
                        columnToActions.Add(aOverride);
                        continue;
                    }

                    columnToActions.Add(aOverride);
                    continue;
                }
            }

            //run through each column and set the matching prop
            for (var tableColumnIndex = 0; tableColumnIndex < table.Header.Count(); tableColumnIndex++)
            {
                if (columnToActions.Any(x => x.ColumnIndex == tableColumnIndex))
                {
                    continue;
                }

                var HeaderItem = table.Header.ElementAt(tableColumnIndex);

                var columnAction = new ColumnToActionContainer <T>()
                {
                    ColumnIndex = tableColumnIndex,
                    ColumnName  = HeaderItem,
                    MatchAction = ColumnActionFactory.GetAction <T>(target, HeaderItem)
                };
                columnToActions.Add(columnAction);
            }

            //Print needs these in the same order as the columns
            var sortedActions = columnToActions.OrderBy(x => x.ColumnIndex);

            //return the mappings of the successful columns
            return(sortedActions);
        }