Esempio n. 1
0
 public Rule(RulePriority priority, string category, ExpressionString condition, ExpressionString costExpression)
 {
     this.Priority = priority;
     this.RuleCategory = category;
     this.Condition = condition;
     this.Cost = costExpression;
 }
Esempio n. 2
0
        public override string ToString()
        {
            ExpressionString str = new ExpressionString();

            this.Accept(str);
            return(str.ToString());
        }
Esempio n. 3
0
        }                                            //Cost calculation formula defined as expression

        public Rule(RulePriority priority, string category, ExpressionString condition, ExpressionString costExpression)
        {
            this.Priority     = priority;
            this.RuleCategory = category;
            this.Condition    = condition;
            this.Cost         = costExpression;
        }
Esempio n. 4
0
        public static string interpolate(List <Object> prepared, JadeModel model)
        {
            StringBuilder result = new StringBuilder();

            foreach (Object entry in prepared)
            {
                if (entry is String)
                {
                    result.Append(entry);
                }
                else if (entry is ExpressionString)
                {
                    ExpressionString expression  = (ExpressionString)entry;
                    string           stringValue = "";
                    string           value       = ExpressionHandler.evaluateStringExpression(expression.getValue(), model);
                    if (value != null)
                    {
                        stringValue = value;
                    }
                    if (expression.isEscape())
                    {
                        stringValue = escapeHTML(stringValue);
                    }
                    result.Append(stringValue);
                }
            }

            return(result.ToString());
        }
        private void ButtonPress(CalculatorKeys parameter)
        {
            if (!string.IsNullOrEmpty(ExpressionString))
            {
                switch (parameter)
                {
                case CalculatorKeys.Equal:
                    EqualClicked();
                    return;

                case CalculatorKeys.Clear:
                    ClearClicked();
                    return;

                case CalculatorKeys.ClearEntry:
                    ClearEntryClicked();
                    return;
                }
            }

            if (!string.IsNullOrEmpty(parameter.GetText()))
            {
                ExpressionString       = ExpressionString.Insert(CurrentCursorPosition, parameter.GetText());
                CurrentCursorPosition += 1;
            }
        }
        public void WriteTo(TextWriter writer)
        {
            if (!string.IsNullOrEmpty(TranslationAttr.Title))
            {
                writer.WriteLine($"### {TranslationAttr.Index + 1}. {TranslationAttr.Title}");
            }

            if (!string.IsNullOrEmpty(TranslationAttr.Description))
            {
                writer.WriteLine($"{TranslationAttr.Description.Trim()}");
            }

            var desc = GetComments(TranslationAttr.ExpressionDescription, "\\");

            writer.WriteLine($"```csharp\n// Linq expression:\n{desc}{ExpressionString.Trim()}\n```");

            if (!string.IsNullOrEmpty(TranslationAttr.SqlDescription))
            {
                writer.WriteLine(TranslationAttr.SqlDescription.Trim());
            }

            desc = GetComments(TranslationAttr.SqlDescription, "--");

            writer.WriteLine($"```sql\n-- Transalted Sql:\n{desc}{Sql.Trim()}\n```");
        }
        private void ClearEntryClicked()
        {
            if (CurrentCursorPosition == 0)
            {
                return;
            }

            ExpressionString       = ExpressionString.Remove(CurrentCursorPosition - 1, 1);
            CurrentCursorPosition -= 1;
        }
        public override CompileResult Compile()
        {
            string exp = string.Empty;
            var    decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;

            if (decimalSeparator == ",")
            {
                exp = ExpressionString.Replace('.', ',');
            }
            return(new CompileResult(double.Parse(exp), DataType.Decimal));
        }
Esempio n. 9
0
        private string ValidateExpressionString()
        {
            if (FormatConditionType != FormatConditionType.Default)
            {
                return(null);
            }

            if (ExpressionString.IsNullOrEmptyAfterTrim())
            {
                return(Resources.StringResources.StyleOptionConditionNotDefined);
            }

            return(Parent.ValidateExpression(ExpressionString));
        }
Esempio n. 10
0
        public static List <Object> prepareInterpolate(string str, bool xmlEscape)
        {
            int start  = 0;
            var result = new List <Object>();

            foreach (Match matcher in interpolationPattern.Matches(str))
            {
                string before = str.Substring(start, matcher.Index - start);
                if (xmlEscape)
                {
                    before = escapeHTML(before);
                }
                result.Add(before);

                bool   escape = matcher.Groups[1].Length < 1;
                string flag   = matcher.Groups[2].Value;
                string code   = matcher.Groups[3].Value;

                if (escape)
                {
                    string escapedExpression = matcher.Groups[0].Value.Substring(1);
                    if (xmlEscape)
                    {
                        escapedExpression = escapeHTML(escapedExpression);
                    }
                    result.Add(escapedExpression);
                }
                else
                {
                    ExpressionString expression = new ExpressionString(code);
                    if (flag.Equals("#"))
                    {
                        expression.setEscape(true);
                    }
                    result.Add(expression);
                }
                start = matcher.Index + matcher.Value.Length;
                var match = matcher.NextMatch();
            }
            string last = str.Substring(start);

            if (xmlEscape)
            {
                last = escapeHTML(last);
            }
            result.Add(last);

            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Normalizes the expression.
        /// </summary>
        /// <returns>The normalized expression.</returns>
        public string NormalizeExpression()
        {
            // Split string to list.
            var expressionList = ExpressionString.Split(' ');

            for (int i = 0; i < expressionList.Count(); i++)
            {
                var token = expressionList[i];

                foreach (var o in Operators)
                {
                    if (o.Value.AlternativeNames.Contains(token))
                    {
                        expressionList[i] = o.Key;
                    }
                }
            }

            NormalizedExpression = String.Join(" ", expressionList);
            return(NormalizedExpression);
        }
        public void DynamicExpressionParser_ParseLambda_UseParameterizedNamesInDynamicQuery_ForNullableProperty_true(string propName, string valueString)
        {
            // Assign
            var config = new ParsingConfig
            {
                UseParameterizedNamesInDynamicQuery = true
            };

            // Act
            var    expression         = DynamicExpressionParser.ParseLambda <SimpleValuesModel, bool>(config, false, $"{propName} = {valueString}");
            string expressionAsString = expression.ToString();

            // Assert
            var queriedProp               = typeof(SimpleValuesModel).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public);
            var queriedPropType           = queriedProp.PropertyType;
            var queriedPropUnderlyingType = Nullable.GetUnderlyingType(queriedPropType);

            Check.That(expressionAsString).IsEqualTo($"Param_0 => (Param_0.{propName} == {ExpressionString.NullableConversion($"value(System.Linq.Dynamic.Core.Parser.WrappedValue`1[{queriedPropUnderlyingType}]).Value")})");
            dynamic constantExpression = ((MemberExpression)(((expression.Body as BinaryExpression).Right as UnaryExpression).Operand)).Expression as ConstantExpression;
            object  wrapperObj         = constantExpression.Value;

            var    propertyInfo = wrapperObj.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public);
            object value        = propertyInfo.GetValue(wrapperObj);

            Check.That(value).IsEqualTo(Convert.ChangeType(valueString, Nullable.GetUnderlyingType(queriedPropType) ?? queriedPropType));
        }