Getting error on making class IEnumerable

447 Views Asked by At

I am trying to inherit the FarPoint.Win.Spread.FpSpread class and implement IEnumerable<FarPoint.Win.Spread.Row> so that i should be able to apply linq on FarPoint spread rows or cells. I tried multiple ways but i keep getting errors:

class myspread : FarPoint.Win.Spread.FpSpread, IEnumerable<FarPoint.Win.Spread.Row>
{
    public IEnumerator<FarPoint.Win.Spread.Row> GetEnumerator()
    {
        return myspread.GetEnumerator();// Error on this line
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

Second try:

class myspread : FarPoint.Win.Spread.Row, IEnumerable<FarPoint.Win.Spread.Row>
{
    public IEnumerator<FarPoint.Win.Spread.Row> GetEnumerator()
    {
        return myspread.GetEnumerator();// Error on this line
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

Third try:

class myspread : FarPoint.Win.Spread.Cells, IEnumerable<FarPoint.Win.Spread.Cells>
{
    public IEnumerator<FarPoint.Win.Spread.Row> GetEnumerator()
    {
        return myspread.GetEnumerator();// Error on this line
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

I want to be able to apply linq on a lot of objects on a FarPoint sheet

Now the above data could be in lacs - i need to do a lot of formatting on the above data and update values on some conditions. How can i achieve this?

1

There are 1 best solutions below

0
On

In all cases you indicate that the following line is generating the error:

return myspread.GetEnumerator();// Error on this line

Without knowing more about your code we can't really get to the bottom of this. It looks like you're trying to call the GetEnumerator method statically on the myspread class, which is probably not what you'd like it to do.

I assume that you want your class to provide enumeration over the rows in the active sheet. Looking at the documentation here, and specifically the docs for the Rows collection, I'll make some guesses about how it might look:

class myspread : FarPoint.Win.Spread.FpSpread,
    IEnumerable<FarPoint.Win.Spread.Row>
{
    public IEnumerable<FarPoint.Win.Spread.Row> GetEnumerator()
    {
        var rows = ActiveSheet.Rows;
        for (int i = 0; i < rows.Count; ++i)
            yield return rows.Item[i];
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

Of course if the Rows collection implemented IEnumerable<Row> then this would be simply a matter of doing:

    public IEnumerable<FarPoint.Win.Spread.Row> GetEnumerator()
    {
        return ActiveSheet.Rows;
    }

The FarPoint documentation doesn't indicate any support for IEnumerable<Row> in the collection however.