protected MethodInfo GetOverloadedBinaryOperator(string name, object operation) { var leftType = MyLeftChild.ResultType; var rightType = MyRightChild.ResultType; var binder = new BinaryOperatorBinder(leftType, rightType); // If both arguments are of the same type, pick either as the owner type if (object.ReferenceEquals(leftType, rightType)) { return Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType); } // Get the operator for both types MethodInfo leftMethod = null; MethodInfo rightMethod = null; leftMethod = Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType); rightMethod = Utility.GetOverloadedOperator(name, rightType, binder, leftType, rightType); // Pick the right one if (leftMethod == null & rightMethod == null) { // No operator defined for either return null; } else if (leftMethod == null) { return rightMethod; } else if (rightMethod == null) { return leftMethod; } else { // Ambiguous call base.ThrowAmbiguousCallException(leftType, rightType, operation); return null; } }
/// <summary> /// Promote the left and right operand types /// </summary> /// <param name="binaryOperatorKind">the operator kind</param> /// <param name="leftNode">the left operand</param> /// <param name="rightNode">the right operand</param> /// <param name="typeReference">type reference for the result BinaryOperatorNode.</param> public virtual void PromoteBinaryOperandTypes( BinaryOperatorKind binaryOperatorKind, ref SingleValueNode leftNode, ref SingleValueNode rightNode, out IEdmTypeReference typeReference) { typeReference = null; BinaryOperatorBinder.PromoteOperandTypes(binaryOperatorKind, ref leftNode, ref rightNode); }
public void CollectionRightTokenShouldFail() { this.binaryOperatorBinder = new BinaryOperatorBinder(this.BindMethodThatReturnsQueryNode, /*resolver*/ null); this.leftQueryNode = new ConstantNode("People"); this.rightQueryNode = new EntitySetNode(this.model.FindDeclaredEntitySet("People")); var binaryOperatorToken = new BinaryOperatorToken(BinaryOperatorKind.Equal, new LiteralToken("foo"), new LiteralToken("bar")); Action bind = () => this.binaryOperatorBinder.BindBinaryOperator(binaryOperatorToken); bind.Throws <ODataException>(Strings.MetadataBinder_BinaryOperatorOperandNotSingleValue("Equal")); }
protected MethodInfo GetOverloadedBinaryOperator(string name, object operation) { Type leftType = MyLeftChild.ResultType; Type rightType = MyRightChild.ResultType; BinaryOperatorBinder binder = new BinaryOperatorBinder(leftType, rightType); // If both arguments are of the same type, pick either as the owner type if (object.ReferenceEquals(leftType, rightType)) { return(Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType)); } // Get the operator for both types MethodInfo leftMethod = default(MethodInfo); MethodInfo rightMethod = default(MethodInfo); leftMethod = Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType); rightMethod = Utility.GetOverloadedOperator(name, rightType, binder, leftType, rightType); // Pick the right one if (leftMethod == null & rightMethod == null) { // No operator defined for either return(null); } else if (leftMethod == null) { return(rightMethod); } else if (rightMethod == null) { return(leftMethod); } else if (object.ReferenceEquals(leftMethod, rightMethod)) { // same operator for both (most likely defined in a common base class) return(leftMethod); } else { // Ambiguous call base.ThrowAmbiguousCallException(leftType, rightType, operation); return(null); } }
protected MethodInfo?GetOverloadedBinaryOperator(string name, object operation) { var leftType = LeftChild.ResultType; var rightType = RightChild.ResultType; var binder = new BinaryOperatorBinder(leftType, rightType); // If both arguments are of the same type, pick either as the owner type if (ReferenceEquals(leftType, rightType)) { return(Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType)); } // Get the operator for both types var leftMethod = Utility.GetOverloadedOperator(name, leftType, binder, leftType, rightType); var rightMethod = Utility.GetOverloadedOperator(name, rightType, binder, leftType, rightType); // Pick the right one if (leftMethod == null & rightMethod == null) { // No operator defined for either return(null); } if (leftMethod == null) { return(rightMethod); } if (rightMethod == null) { return(leftMethod); } //Ambiguous call throw CreateCompileException(CompileErrors.AmbiguousOverloadedOperator, CompileExceptionReason.AmbiguousMatch, leftType.Name, rightType.Name, operation); }
public void Init() { this.shouldReturnLeft = true; this.binaryOperatorBinder = new BinaryOperatorBinder(this.BindMethodThatReturnsSingleValueQueryNode, /*resolver*/ null); }
public BinaryOperatorBinderTests() { this.shouldReturnLeft = true; this.binaryOperatorBinder = new BinaryOperatorBinder(this.BindMethodThatReturnsSingleValueQueryNode, ODataUriResolver.GetUriResolver(null)); }