Ejemplo n.º 1
0
        IEnumerable <T> ProcessCore <T>(Func <IColumnLocation, IColumn, T> func, IColumnLocation currentLoc)
        {
            var list = new List <T> {
                func(currentLoc, this)
            };

            list.AddRange(_content.Extract(f, g));
            return(list);

            IEnumerable <T> f(IEnumerable <IRow> rows)
            {
                var results  = new List <T>();
                var rowArray = rows.Select(row => new Row(row)).ToArray();
                var rowCount = rowArray.Length;

                for (int i = 0; i < rowCount; i++)
                {
                    var colArray = rowArray[i].Columns.Select(col => new Column(col)).ToArray();
                    var colCount = colArray.Length;

                    for (int j = 0; j < colCount; j++)
                    {
                        results.AddRange(colArray[j].ProcessCore(func, currentLoc.Nest(i, j)));
                    }
                }

                return(results);
            }

            IEnumerable <T> g(object obj) => Array.Empty <T>();
        }
Ejemplo n.º 2
0
        void ActOnRowsCore(Action <IRowLocation, IRow> action, IColumnLocation currentLoc)
        {
            _content.Act(f, g);

            void f(IEnumerable <IRow> rows)
            {
                var rowArray = rows.Select(row => new Row(row)).ToArray();
                var rowCount = rowArray.Length;

                for (int i = 0; i < rowCount; i++)
                {
                    action(currentLoc.NestOpen(i), rowArray[i]);

                    var colArray = rowArray[i].Columns.Select(col => new Column(col)).ToArray();
                    var colCount = colArray.Length;

                    for (int j = 0; j < colCount; j++)
                    {
                        colArray[j].ActOnRowsCore(action, currentLoc.Nest(i, j));
                    }
                }
            }

            void g(object obj)
            {
            }
        }
Ejemplo n.º 3
0
        object GetEndpointCore(IColumnLocation columnLocation, IColumn currentCol)
        {
            return(currentCol.Content.Extract(f, g));

            object f(IEnumerable <IRow> rows)
            {
                if (columnLocation.RowNesting.Count() == 0)
                {
                    throw new ArgumentException("Nestings don't navigate to an endpoint.");
                }

                var rowIndex = columnLocation.RowNesting.First();
                var colIndex = columnLocation.ColumnNesting.First();

                var rowArray = rows.Select(r => new Row(r)).ToArray();
                var rowCount = rowArray.Count();

                if (rowIndex >= rowCount)
                {
                    throw new ArgumentException($"Row index out of range; Pair: [{rowIndex}, {colIndex}].");
                }

                var colArray = rowArray[rowIndex].Columns.ToArray();
                var colCount = colArray.Count();

                if (colIndex >= colCount)
                {
                    throw new ArgumentException($"Column index out of range; Pair: [{rowIndex}, {colIndex}].");
                }

                int currNestingSize = columnLocation.RowNesting.Count();

                return(GetEndpointCore(new ColumnLocation(
                                           columnLocation.RowNesting.TakeLast(currNestingSize - 1).ToArray(),
                                           columnLocation.ColumnNesting.TakeLast(currNestingSize - 1).ToArray()),
                                       colArray[colIndex]));
            }

            object g(object obj)
            {
                if (columnLocation.RowNesting.Count() != 0)
                {
                    throw new ArgumentOutOfRangeException("Row and column nesting out of range.");
                }
                return(obj);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Indexer works like <see cref="GetEndpoint(IColumnLocation)"/>.
 /// </summary>
 /// <param name="columnLocation">Location pointing to an endpoint.</param>
 /// <returns></returns>
 public object this[IColumnLocation columnLocation] => GetEndpoint(columnLocation);
Ejemplo n.º 5
0
 public object GetEndpoint(IColumnLocation columnLocation)
 {
     return(GetEndpointCore(columnLocation, this));
 }