Sum of expression lamba on List
See original GitHub issueHi
I was trying to make an evaluation, a Sum on a List, but I’m getting an error: CodingSeb.ExpressionEvaluator.ExpressionEvaluatorSyntaxErrorException: ‘Function [Sum] unknown in expression : [Sum(x => x.Nombre == “uno” ? (x.Valor ?? 0m) : 0m)]’
What am I doing wrong? or it is not supported?
var Lista = new List<Test>() { new Test { Nombre = "uno", Valor = 1.11m }, new Test { Nombre = "uno", Valor = 2.22m }, new Test { Nombre = "uno", Valor = null }, new Test { Nombre = "dos", Valor = 3.33m } };
string script = "Sum(x => x.Nombre == \"uno\" ? (x.Valor ?? 0m) : 0m)";
ExpressionEvaluator Eval = new ExpressionEvaluator()
{
StaticTypesForExtensionsMethods = new List<Type> { typeof(Enumerable) },
Namespaces = new List<string>() { "System", "System.Linq"},
OptionVariableAssignationActive = false,
OptionPropertyOrFieldSetActive = false,
CacheTypesResolutions = true
};
Eval.Context = Lista;
var result = Eval.Evaluate(script);
// ***********************************************************************
public class Test
{
public string Nombre { get; set; }
public decimal? Valor { get; set; }
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
python - Finding a sum in nested list using a lambda function
One approach is to use a generator expression: total = sum(int(v) for name,v in table).
Read more >Python Sum Lambda [3 different ways]
Lambda to get sum of a list using reduce. We can leverage the above lambda to get the sum of two elements to...
Read more >Python program to find the sum of elements of a list using ...
Here, we will write a Python program to find the sum of elements of a list using lambda function. ... Lambda functions in...
Read more >Python Lambda Functions with Examples | H2kinfosys Blog
The given below is the sum lambda function sum = lambda a, b: a + b ... The filter function takes a function...
Read more >Python: Calculate the sum of the positive and negative ...
Write a Python program to calculate the sum of the positive and negative numbers of a given list of numbers using the lambda...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi
Yes I tested and it’s working perfectly fine. it’s the perfect solution for indexing… and for calling context methods…
Actually this code is in production already… 😃
new version 1.4.30.0 introduce the this keyword to manage extention methods and indexing on Context. Thanks @TheoVC.