0

I'm looking at this open source project, and the fluent api looks like:

baseEngine.For<Foo1>()
            .Setup(f => f.Value)
              .MustEqual(1);

Then MustEqual method's parameter list it:

 public static M MustEqual<M, T, R>(this IMustPassRule<M, T, R> mpr, R value)
 {
    return mpr.MustPassRule(new EqualRule<R>(value));
 }

for more details: http://rulesengine.codeplex.com/SourceControl/changeset/view/9077#137411

So what I'm trying to get at is, the call to MustEqual is being passed only a single arguement, since it is fluent, is it somehow implicitly picking up other required parameters from the previously chained calls?

1
  • Are you talking about "this IMustPassRule<M, T, R> mpr"? If so then this is a C# construct to create an extension method for the IMustPassRule interface Commented Oct 18, 2011 at 16:18

3 Answers 3

2

The state gets stored in the object itself by those previous methods, if necessary.

Sign up to request clarification or add additional context in comments.

Comments

0

You are looking at an Extension Method.

Extension Methods allow static methods to be invoked with instance method syntax. For instance,

something.MustEqual(1);

is equivalent to

RulesHelper.MustEqual(something, 1);

Comments

0

A nice example can be found in LINQ

The IEnumerable<T>.OrderBy returns an IOrderedEnumerable<T>

This second interface keeps track of the order so the IOrderedEnumerable<T>.ThenBy is able to do a sub-sort. To make things smooth the interface derives from IEnumerable<T>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.