public static BinaryExpression AndAlso(Expression left, Expression right, MethodInfo method)
{
RequiresCanRead(left, nameof(left));
RequiresCanRead(right, nameof(right));
Type returnType;
if (method == null)
{
if (left.Type == right.Type)
{
if (left.Type == typeof(bool))
{
return new LogicalBinaryExpression(ExpressionType.AndAlso, left, right);
}
else if (left.Type == typeof(bool?))
{
return new SimpleBinaryExpression(ExpressionType.AndAlso, left, right, left.Type);
}
}
method = GetUserDefinedBinaryOperator(ExpressionType.AndAlso, left.Type, right.Type, "op_BitwiseAnd");
if (method != null)
{
ValidateUserDefinedConditionalLogicOperator(ExpressionType.AndAlso, left.Type, right.Type, method);
returnType = (left.Type.IsNullableType() && TypeUtils.AreEquivalent(method.ReturnType, left.Type.GetNonNullableType())) ? left.Type : method.ReturnType;
return new MethodBinaryExpression(ExpressionType.AndAlso, left, right, returnType, method);
}
throw Error.BinaryOperatorNotDefined(ExpressionType.AndAlso, left.Type, right.Type);
}
ValidateUserDefinedConditionalLogicOperator(ExpressionType.AndAlso, left.Type, right.Type, method);
returnType = (left.Type.IsNullableType() && TypeUtils.AreEquivalent(method.ReturnType, left.Type.GetNonNullableType())) ? left.Type : method.ReturnType;
return new MethodBinaryExpression(ExpressionType.AndAlso, left, right, returnType, method);
}