ExpressionEvaluator
                                
                                
                                
                                    ExpressionEvaluator copied to clipboard
                            
                            
                            
                        Linq Select throws exception (ValueTuple?) issue?
context.AddVariable("list1", new int[] { 1, 2, 3, 8 });
context.AddVariable("list2", new int[] { 4, 5, 6, 7 });
var test = context.Evaluate("list1.Cast<int>().Select<int, int>((item, i) => item - list1[i]).Cast<int>().Sum()");
throws:
ExpressionEvaluatorSyntaxErrorException : The call of the method "Sum" on type [System.Linq.Enumerable+SelectArrayIterator`2[System.Int32,System.Int32]] generate this error : Index was outside the bounds of the array.
With Zip or EquiZip it works fine:
list1.Cast<int>().EquiZip<int, int, int>(list2, (l1, l2) => l1 + l2).Cast<int>().Sum()"
What is wrong with select?
EDIT: Seems like it's an issue when using ValueTuple.... Maybe this is not supported?
Here is a simple .NET fiddle example which shows the unexpected behaviour:
This line breaks it: https://github.com/codingseb/ExpressionEvaluator/blob/365551a87cda0de63a18d603f257354460b1f8c3/CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs#L3425
For some reason the internalDelegate args contains 1 item, and should contain 2 in this case... https://github.com/codingseb/ExpressionEvaluator/blob/365551a87cda0de63a18d603f257354460b1f8c3/CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs#L3504-L3516
I guess this overload requires some special handling?
FYI this is still an issue in 1.5.0-alpha releases