简体   繁体   中英

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

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?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM