public override ExprNode Validate(ExprValidationContext validationContext) { if (ChildNodes.Length != 2) { throw new ExprValidationException("BitWise node must have 2 parameters"); } var typeOne = ChildNodes[0].Forge.EvaluationType.GetBoxedType(); var typeTwo = ChildNodes[1].Forge.EvaluationType.GetBoxedType(); CheckNumericOrBoolean(typeOne); CheckNumericOrBoolean(typeTwo); if (typeOne.IsFloatingPointClass() || typeTwo.IsFloatingPointClass()) { throw new ExprValidationException( "Invalid type for bitwise " + BitWiseOpEnum.ComputeDescription + " operator"); } if (typeOne != typeTwo) { throw new ExprValidationException( "Bitwise expressions must be of the same type for bitwise " + BitWiseOpEnum.ComputeDescription + " operator"); } var computer = BitWiseOpEnum.GetComputer(typeOne); _forge = new ExprBitWiseNodeForge(this, typeOne, computer); return null; }
/// <summary> /// Returns number or bool computation for the target coercion type. /// </summary> /// <param name="value">The value.</param> /// <param name="coercedType">target type</param> /// <returns>number cruncher</returns> public static Computer GetComputer(this BitWiseOpEnum value, Type coercedType) { if ((coercedType != typeof(byte?)) && (coercedType != typeof(byte?)) && (coercedType != typeof(short?)) && (coercedType != typeof(int?)) && (coercedType != typeof(long?)) && (coercedType != typeof(bool?))) { throw new ArgumentException("Expected base numeric or bool type for computation result but got type " + coercedType); } MultiKeyUntyped key = new MultiKeyUntyped(new Object[] { coercedType, value }); return(Computers[key]); }
public static String GetExpressionText(this BitWiseOpEnum value) { switch (value) { case BitWiseOpEnum.BAND: return("&"); case BitWiseOpEnum.BOR: return("|"); case BitWiseOpEnum.BXOR: return("^"); } throw new ArgumentException("invalid value", "value"); }
/// <summary> /// Ctor. /// </summary> /// <param name="bitWiseOpEnum">type of math</param> public ExprBitWiseNode(BitWiseOpEnum bitWiseOpEnum) { BitWiseOpEnum = bitWiseOpEnum; }
public void QExprBitwise(ExprNode exprNode, BitWiseOpEnum bitWiseOpEnum) { }
/// <summary> /// Ctor - for use to create an expression tree, without child expression. /// <para/> /// Use add methods to add child expressions to acts upon. /// </summary> /// <param name="binaryOp">the binary operator</param> public BitwiseOpExpression(BitWiseOpEnum binaryOp) { _binaryOp = binaryOp; }
/// <summary>Returns string rendering of enum.</summary> /// <returns>bitwise operator string</returns> public static String GetComputeDescription(this BitWiseOpEnum value) { return(GetExpressionText(value)); }
public void QExprBitwise( string text, BitWiseOpEnum bitWiseOpEnum) { }