Skip to content

Match against collection of polymorphic types #33

Description

@cocowalla

Thanks for this library, it's wonderfully straightforward!

Now, my problem - consider a class and hierarchy like this:

public class Order
{
    public IList<IItem> Items { get; set; }
}

public interface IItem
{
    Guid Id { get; set; }
}

public class StandardItem : IItem
{
    ...
}

public class SpecialItem : IItem
{
    public string Name { get; set; }
}

What I'd like to do is create a Rule that can match on the Items collection for a specific type of IItem, for example to match only on SpecialItem instances:

var rule = Rule.Any(nameof(Order.Items), Rule.Create(nameof(SpecialItem.Name), MreOperator.Equal, "My Special Item Name"));

The above doesn't work, because:

MicroRuleEngine.RulesException: Cannot find property Name in class IItem ("Name")

I guess what's really needed here is some way to "pre-filter" the collection with Linq's .OfType<SpecialItem>(). Is something like this possible already? Otherwise, are you able to offer a few pointers about the best way to add this functionality? (happy to submit a PR)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions