Kooboo.Commerce.Rules.Conditions.ExpressionEvaluator.Visit C# (CSharp) Method

Visit() protected method

protected Visit ( ComparisonExpression exp ) : void
exp Kooboo.Commerce.Rules.Conditions.Expressions.ComparisonExpression
return void
        protected override void Visit(ComparisonExpression exp)
        {
            var paramName = exp.Param.ParamName;
            var param = _availableParameters.FirstOrDefault(x => x.Name == paramName);
            if (param == null)
                throw new UnrecognizedParameterException("Unrecognized parameter \"" + paramName + "\" or it's not accessable in currect context.");

            var @operator = _comparisonOperators.Find(exp.Operator);
            if (@operator == null)
                throw new UnrecognizedComparisonOperatorException("Unrecognized comparison operator \"" + exp.Operator + "\".");

            var result = false;

            var paramValue = param.ResolveValue(_dataContext);
            if (paramValue != null)
            {
                var paramType = paramValue.GetType();
                object conditionValue = null;

                if (paramType.IsEnum)
                {
                    conditionValue = Enum.Parse(paramType, exp.Value.Value);
                }
                else
                {
                    conditionValue = Convert.ChangeType(exp.Value.Value, paramType);
                }

                result = @operator.Apply(param, paramValue, conditionValue);
            }

            _results.Push(result);
        }

Same methods

ExpressionEvaluator::Visit ( LogicalBindaryExpression exp ) : void