Design issues and implementing Enumerable.AsEnumerable<FarPoint.Win.Spread.Row>

微笑、不失礼 提交于 2019-12-13 09:35:43

问题


How can i make a datatype return IEnumerable<datatype> if it does not have AsEnumerable() method. For example:

FarPointSpread1.ActiveSheet.Rows[e.Row]

does not contain AsEnumerable() so i cannot do this

FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable()

e.Row is the current row in the spread's activesheet and i am expecting to be able to do something like this:

IEnumerable<FarPoint.Win.Spread.Row> = FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable();

I want to iterate over all fields in a row and set values on runtime - which will come from database. Is there a way i can achieve this? If there is some workaround please let me know with some examples. Even if the example cannot be shown using Farpoint - any other kind of example is welcome. Thanks in advance.


回答1:


You can create an extension method. An example without FarPoint is:

public class TestClass
{
    public IReadOnlyCollection<int> Values { get; set; }
}

public static class TestClassExtensions
{
    public static IEnumerable<int> AsEnumerable(this TestClass cls)
    {
        return cls.Values.AsEnumerable();
    }
}

// Call
var cls = new TestClass();
var enum = cls.AsEnumerable();

This sample shows the general structure of an extension method - of course it is very simplified as TestClass contains the values already in a matching form. You'd implement the extension method so that it contains the logic to enumerable the rows for FarPoint.
As far as I understand your question, you want to extend a single row and enumerate the values of the fields. You'd use the data type of the row and enumerate the fields in the extension methods.



来源:https://stackoverflow.com/questions/20324797/design-issues-and-implementing-enumerable-asenumerablefarpoint-win-spread-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!