Code Monkey home page Code Monkey logo

Comments (4)

BardezAnAvatar avatar BardezAnAvatar commented on September 22, 2024

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 as GenericImmutableArray??

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.

BardezAnAvatar avatar BardezAnAvatar commented on September 22, 2024

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.

BardezAnAvatar avatar BardezAnAvatar commented on September 22, 2024

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.

asulwer avatar asulwer commented on September 22, 2024

i made some changes to my fork which may affect this question

from rulesengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.