What's the exact syntax to concat 2 constraints in Rhino Mocks framework?

80 views Asked by At

I see in the Rhino source code the following code:

// Summary:
//     Or operator for constraints
public static AbstractConstraint operator |(AbstractConstraint c1, AbstractConstraint c2);

But in practice, I can use either | or ||.

Similarly, both & and && work the same way.

Why is this happening?

1

There are 1 answers

0
argaz On BEST ANSWER

This is actually a C# issue. You can't overload the conditional logical operators - && and || directly, in order to overload them the programmer has to overload the &,|, true and false operators, and those operators are used to evaluate an expression containing the && and || operators. More details in this article.

Concerning Rhino Mocks, he chose to implement the true and false operators in a way that prevents short circuiting and makes the && and || operators equivalent to & and |, ILSpy output:

public static bool operator false(AbstractConstraint c)
{
    return false;
}

public static bool operator true(AbstractConstraint c)
{
    return false;
}