Closed lichengxihuang closed 1 year ago
@lichengxihuang can you share which OS and dotnet version you are using?
@lichengxihuang can you share which OS and dotnet version you are using? I am using Windows 11 and .net 7.0.
Are there ways to use List, Set, Dictionary as the LocalParam?
If I change the above code to the following
Rule rule = new Rule
{
RuleName = "Test Rule",
LocalParams = new List<LocalParam>
{
new LocalParam
{
Name = "myList",
Expression = "new List<int> { 1, 2, 3, 4, 5 }"
}
},
SuccessEvent = "Count is within tolerance.",
ErrorMessage = "Not as expected.",
Expression = "myList.Where(x => x < 3).Contains(myObj.Count)",
RuleExpressionType = RuleExpressionType.LambdaExpression
};
It returns error
Error while compiling rule
Test Rule
: Type 'List' not found, in ScopedParam: myList
@lichengxihuang the original issue is fixed in v5.0.2
Are there ways to use List, Set, Dictionary as the LocalParam?
Well creating List
using new might not work as generics are not supported in expression.
You can however create an array and do .ToList()
. I havent tried similar approach for Set
or Dictionary
but it may work till some extent.
If not there is always a workaround to write a custom Utils class and generate it for you. In your example this should work:
new int[] { 1, 2, 3, 4, 5 }.ToList()
Here is my code snippet, and I am using the LocalParam. The answer seems incorrect.
This gives results both true, which is incorrect, as the second result should be false.
Instead, if I replace the localParam with the constant number 3, the results returned are correct: True, False.