问题
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