Skip to content

Extend termination criteria #28

Description

@balintn22

Hi,

I really like the simple approach, but imho DataExtractor.GetData() termination is lacking: it can either terminate based on the row number or on the value of a single property.
I propose to extend the termination test like this:

`
///


/// Obtains the entities for the columns previously configured.
/// The indicates the initial row that will be read,
/// the data extraction will only occur while the predicate returns true.
/// It'll get executed receiving the row index as parameter before extracting the data of each row.
///

/// The initial row to start the data extraction.
/// The condition that is evaulated for each row. The last fetched record is
/// passed as the argument to the predicate. The condition is evaluated before the row under test is
/// returned. Row fetching stops when the test returns false.
/// Returns an with the data of the columns.
public IEnumerable GetDataUntil(int fromRow, Func<int, TRow, bool> whileFunc)
{
if (whileFunc is null)
throw new ArgumentNullException(nameof(whileFunc));

        int row = fromRow;
        while(true)
        {
            var dataInstance = new TRow();

            bool continueExecution = true;
            for (int index = 0; continueExecution && index < this.propertySetters.Count; index++)
                continueExecution = this.propertySetters[index].SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            if (!continueExecution)
            {
                yield return dataInstance;
                break;
            }

            foreach (var collectionPropertySetter in this.collectionColumnSetters)
                collectionPropertySetter.SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            foreach (var simpleCollectionColumnSetter in this.simpleCollectionColumnSetters)
                simpleCollectionColumnSetter.SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            if(!whileFunc(row, dataInstance))
                break;

            yield return dataInstance;

            row++;
        }
    }

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions