/// <summary>
        /// Do the specified UnaryOperation for the value and returns the result.
        /// </summary>
        /// <param name="operation">The binary operation to perform.</param>
        /// <param name="value">The value.</param>
        /// <returns>Result of the operation.</returns>
        public virtual QueryScalarValue Evaluate(QueryUnaryOperation operation, QueryScalarValue value)
        {
            Func <object, Type, object> evaluationMethod = null;

            switch (operation)
            {
            case QueryUnaryOperation.LogicalNegate:
                return(this.BooleanType.CreateValue(!(bool)value.Value));

            case QueryUnaryOperation.Negate:
                evaluationMethod = ArithmeticEvaluationHelper.Negate;
                break;

            case QueryUnaryOperation.BitwiseNot:
                evaluationMethod = ArithmeticEvaluationHelper.BitwiseNot;
                break;

            default:
                throw new TaupoNotSupportedException("Unsupported query unary operation.");
            }

            ExceptionUtilities.Assert(evaluationMethod != null, "evaluationMethod should not be null.");
            Type   clrType = ((QueryClrPrimitiveType)value.Type).ClrType;
            object result  = evaluationMethod(value.Value, clrType);

            return(value.Type.CreateValue(result));
        }
        /// <summary>
        /// Determines whether a typed data can do certain operation
        /// </summary>
        /// <param name="operation">the operation</param>
        /// <param name="sourceType">the type of data to operate on</param>
        /// <returns>Value <c>true</c> if operation can be performed; otherwise, <c>false</c>.</returns>
        public bool Supports(QueryUnaryOperation operation, QueryScalarType sourceType)
        {
            switch (operation)
            {
            case QueryUnaryOperation.LogicalNegate:
                return(((IQueryClrType)sourceType).ClrType == typeof(bool));

            default:
                throw new TaupoNotSupportedException("Unsupported query unary operation.");
            }
        }
Exemple #3
0
 /// <summary>
 /// Determines whether data of this type can do certain operation
 /// </summary>
 /// <param name="operation">the operation</param>
 /// <returns>Value <c>true</c> if operation can be performed; otherwise, <c>false</c>.</returns>
 public bool Supports(QueryUnaryOperation operation)
 {
     return(this.EvaluationStrategy.Supports(operation, this));
 }
 /// <summary>
 /// Determines whether data of this type can do certain operation
 /// </summary>
 /// <param name="operation">the operation</param>
 /// <returns>Value <c>true</c> if operation can be performed; otherwise, <c>false</c>.</returns>
 public bool Supports(QueryUnaryOperation operation)
 {
     return this.EvaluationStrategy.Supports(operation, this);
 }
 /// <summary>
 /// Do the specified UnaryOperation for the value and returns the result.
 /// </summary>
 /// <param name="operation">The binary operation to perform.</param>
 /// <param name="value">The value.</param>
 /// <returns>Result of the operation.</returns>
 public QueryScalarValue Evaluate(QueryUnaryOperation operation, QueryScalarValue value)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }