Comments (4)
Root cause has been identified:
I have a (very) complex object called ClaimDto, which has its own implementations. One child object is the ClaimLine, as referenced above:
public interface IClaimLine
{
[redacted]
IReadOnlyList<string> Modifiers { get; }
[redacted]
}
public class ClaimLine : IClaimLine
{
[redacted]
//The original property
public ClaimLineModifiers Modifiers => _modifiers;
//The interface's property
IReadOnlyList<string> IClaimLine.Modifiers => _modifiers.Items().Select(c => c.Modifier).ToList();
[redacted]
}
public class ClaimLineModifiers : GenericImmutableArray<ClaimLineModifier>
{
[redacted]
}
public class ClaimLineModifier
{
[redacted]
public string Modifier {get; set;}
[redacted]
}
It turns out that the RuleParameter
does not take the type of the reference being passed around (IClaim/IClaimLine) into account, but instead uses the object's type when evaluating the rule.
I uncovered this when screwing around with the expression:
Exception while parsing expression `line.Modifiers.ToList().Any(l => new [] {"25"}.Contains(l))` - Methods on type 'GenericImmutableArray`1' are not accessible
what the [expletive]? why is
line.Modifiers
pinging asGenericImmutableArray
??
I also tried by renaming my interface's Modifiers
to Modifiers2
and referencing the property there; no such property when evaluating against Modifiers2
if it remained an explicit interface implementation.
I suppose my immediate solution would be to cast my line
to IClaimLine
inside of my expression.
from rulesengine.
Oddly, in a separate solution that generates this expression, I am able to load the above without issue in my integration test project. Taking the same expression over to my other solution, however, yields the above exception when running RulesEngine. Both solutions use the exact same NuGet version of RulesEngine (5.0.3), using the same Workflow serialization/deserialization
The reason that Solution A (source of the expression, with tests) worked was because Solution A only had references to the interface and used mock objects to test expressions in RulesEngine locally. Solution B consuming the expressions have the complicated object model, which has conflicting types between the interface's .Modifiers
and the class' .Modifiers
from rulesengine.
I've got a resolution for my solution: I need to do the following for single-instance objects:
As(line, "<<<FullyQualifiedNamespace>>>.IClaimLine")
and for lists:
history.Cast("<<<FullyQualifiedNamespace>>>.IClaim")
I would raise that a suggested feature request would be to specify the type to evaluate a given object as for an additional RuleParameter.Create
. This would allow the expected behavior of passing in an IClaim to evaluate as an IClaim rather than an instance with a complicated and messy legacy model implementation.
It looks like there is such a constructor on RuleParameter
, but it is internal:
internal RuleParameter(string name, Type type, object value = null)
{
Value = Utils.GetTypedObject(value);
Init(name, type);
}
from rulesengine.
i made some changes to my fork which may affect this question
from rulesengine.
Related Issues (20)
- Rule Engine HOT 1
- Ef Derived Class concern HOT 2
- If an execution took an exception in the next runs error message is transfered even if it successes. HOT 3
- Missing syntax highlighting in wiki getting started
- AOT compatibility, and move to System.Text.Json HOT 5
- Dictionary type supports .? HOT 4
- Possibility to choose the execution of all actions or not HOT 1
- Support for Any-Operator on List-Types HOT 2
- How do we pass output of one rule as input to next rule? HOT 1
- Repo maintained anymore? HOT 32
- Strange behavior with UseFastExpressionCompiler = true when local param contains plus operator HOT 1
- ExecuteAllRulesAsync should support a CancellationToken as argument HOT 18
- No applicable method 'IsNullOrWhiteSpace' exists in type 'String' HOT 3
- Caching Issue in Literals Dictionary Causes Valid Expression to Fail HOT 13
- Exception Thrown Upgrading To Latest System.Linq.Dynamic.Core Version HOT 2
- Optional parameters for method calls not supported by expression evaluation
- EnableExceptionAsErrorMessage = false does not actually throw exception, but ignores/supresses it HOT 3
- Mark repository as unmaintained/archive it HOT 1
- Action Workflow and global params do not work together
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rulesengine.