예제 #1
0
        private static Expression BelongsToInverseInterval(Expression variable, Expression from, Expression to)
        {
            var greaterThanOrEqualTo = DynamicBuilder.BuildOperator(ExpressionType.GreaterThanOrEqual, variable, to);
            var lessThanOrEqualFrom  = DynamicBuilder.BuildOperator(ExpressionType.LessThanOrEqual, variable, from);

            return(DynamicBuilder.BuildLogicalAnd(greaterThanOrEqualTo, lessThanOrEqualFrom));
        }
예제 #2
0
        public void TakeStep()
        {
            var addStep = DynamicBuilder.BuildOperator(ExpressionType.Add, Variable, Step);
            var convert = DynamicBuilder.BuildConvert(addStep, typeof(object));
            var assign  = Expression.Assign(Variable, convert);

            assign.RunAndDropValue();

            IsOver = !IsBelongsToInterval(Variable, From, To);
        }
예제 #3
0
        /// <summary>
        /// Determines whether the variable belongs to the specified interval.
        /// </summary>
        /// <remarks>The method checks for both <c>[from, to]</c> and <c>[to, from]</c> intervals.</remarks>
        /// <param name="variable">The variable expression.</param>
        /// <param name="from">The start bound expression.</param>
        /// <param name="to">The end bound expression.</param>
        /// <returns><c>true</c> if the variable belongs to the interval; otherwise, <c>false</c>.</returns>
        internal static bool IsBelongsToInterval(Expression variable, Expression from, Expression to)
        {
            var isBelongsToDirectInterval  = BelongsToDirectInterval(variable, from, to);
            var isBelongsToInverseInterval = BelongsToInverseInterval(variable, from, to);

            var result = DynamicBuilder.BuildLogicalOr(isBelongsToDirectInterval, isBelongsToInverseInterval);

            var resultAsBool = (bool)DynamicBuilder.BuildConvert(result, typeof(bool))
                               .Calculate();

            return(resultAsBool);
        }