0

I haven't done much of C# for last few years and recently I was trying to use NRules for rule engine implementation.

While going through the sample

    Context context = default;
    LastSeat lastSeat = default;
    Seating seating = default;

    When()
        .Match(() => context, c => c.State == ContextState.CheckDone)
        .Match(() => lastSeat) // <=== this one
        .Match(() => seating, s => s.RightSeatId == lastSeat.SeatId);

I couldn't get how the second line in When() method .Match(() => lastSeat) works because when I see the source code of match

public interface ILeftHandSideExpression
{

    public ILeftHandSideExpression Match<TFact>(params Expression<Func<TFact, bool>>[] conditions)
    {
       //some logic here 
        return this;
    }
}

and () => lastSeat doesn't return boolean, I couldn't get my head around this.

I tried mimicking minified version of those lambda around but couldn't get much of idea.

greybeard
  • 2,249
  • 8
  • 30
  • 66
Sakary
  • 5
  • 1
  • I found the answer to it – Sakary May 20 '23 at 04:27
  • It's great that you found the answer, but in case others who find this question are interested, the key point to understand with NRules is that C# DSL is not actually executable code - it is a fluent expression builder, and those match conditions are later compiled into the actual executable delegates. That second match creates an expression to match any fact of the type `LastSeat`. – Sergiy Nikolayev May 21 '23 at 18:24
  • I didnt understand the C# key words params the was creating a confusion, with params key word in function arugument passing empty arrway is not required – Sakary May 22 '23 at 15:56

0 Answers0