I have a C# method that returns very large number of objects. This is to be consumed in Matlab.
namespace MyNameSpace{
public static class MyClass{
public static IEnumerable<MyDataObject> GetVeryLargeResponse(){
while(CheckForSomeFunkyConditionThatsRarelyTrue()){
yield return GetMyNextDataObject();
}
yield break;
}
}
}
In Matlab when I make a call
result = MyClass.GetVeryLargeResponse();
I would expect result to be of type IEnumerable<MyDataObject>, so as to be able to get the Enumerator<MyDataObject> by calling result.GetEnumerator().
Where as I’m getting result which is of type MyNameSpace.<GetVeryLargeResponse>d_3 with no GetEnumerator() method available. I do see one of result‘s Super class being System.Collections.Generic.IEnumerable<MyClass>.
Is there a way I can iterate over this in Matlab or even to ‘cast’ result to IEnumerable<MyClass> in Matlab.
p.s.
- Converting to
Array/IListetc is not feasible due to data volume - This is not duplicate of How can I iterate over a C# IEnumerable in Matlab?, as that is dealing with
IQueryablespecifically. - I’m using Matlab 2010b
The result does have a
GetEnumerator()method – it’s just may be implemented with explicit interface implementation.If Matlab isn’t willing to handle that, you could always write your own mapping type and an extension method to make things simpler:
Then try:
It seems very odd for Matlab not so support this out of the box though…