コード例 #1
0
        public static bool ParseContextElement(Element element, ExpressionTerm expressionPart)
        {
            if (expressionPart.IsValidFunctionByName(".TargetElementName") == true)
            {
                element.TargetElementName = expressionPart.Value;
                return(true);
            }
            else if (expressionPart.IsValidFunctionByName("TargetElementText") == true)
            {
                element.TargetElementText = expressionPart.Value;
                element.TextFunction      = expressionPart.FunctionArgument;
                element.Equal             = expressionPart.ExpressionBooleanCondition;
                return(true);
            }
            else if (expressionPart.IsValidFunctionByRegex("Attribute(.*)\\.Text") == true)
            {
                element.Attributes.Add(new Model.Attribute(expressionPart.FunctionArgument)
                {
                    Text = expressionPart.Value, ExactMatch = true
                });
                return(true);
            }
            else if (expressionPart.IsValidFunctionByRegex("Attribute(.*)\\.Contains") == true)
            {
                element.Attributes.Add(new Model.Attribute(expressionPart.FunctionArgument)
                {
                    Text = expressionPart.Value, Equal = expressionPart.ExpressionBooleanCondition
                });
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public static bool ParsePosition(Element element, ExpressionTerm expressionPart)
        {
            if (expressionPart.IsValidFunctionByName(".Position") == true)
            {
                element.Position = Int32.Parse(expressionPart.Value);
                return(true);
            }

            return(false);
        }
コード例 #3
0
 public static void Parse(Element element, ExpressionTerm expressionTerm)
 {
     foreach (var parser in ElementParser.GetAllParsers())
     {
         bool done = parser(element, expressionTerm);
         if (done == true)
         {
             return;
         }
     }
 }
コード例 #4
0
        private static ExpressionTerm ParseEqualityExpression(Expression operation)
        {
            BinaryExpression be = (BinaryExpression)operation;

            string functionName     = null;
            var    leftExpression   = ParseSubExpressions(be.Left);
            string functionArgument = null;

            if (leftExpression is ExpressionTerm)
            {
                var expr = (ExpressionTerm)leftExpression;
                functionName     = expr.Function;
                functionArgument = expr.FunctionArgument;
            }
            else
            {
                functionName = leftExpression.ToString();
            }

            var expressionTerm = new ExpressionTerm()
            {
                Function = functionName, FunctionArgument = functionArgument
            };

            var rightExpression = ParseSubExpressions(be.Right);

            if (rightExpression is string)
            {
                expressionTerm.Value = rightExpression.ToString();
            }
            if (rightExpression is ExpressionTerm)
            {
                var expr = (ExpressionTerm)rightExpression;
                expressionTerm.Value = expr.Value;
            }
            else
            {
                if (rightExpression.GetType() == typeof(bool))
                {
                    expressionTerm.Value = ((ExpressionTerm)leftExpression).Value;
                    expressionTerm.ExpressionBooleanCondition = (bool)rightExpression;
                }
                else
                {
                    expressionTerm.Value = rightExpression.ToString();
                }
            }
            return(expressionTerm);
        }
コード例 #5
0
        public static void ParseExpression(BinaryExpression chain, Element element)
        {
            ElementParser.ThrowIfNotSupported(chain);

            if (chain.Left is BinaryExpression)
            {
                Parse(element, (ExpressionTerm)ParseSubExpressions(chain.Right));
                ParseExpression((BinaryExpression)chain.Left, element);
            }
            else
            {
                ExpressionTerm expressionTerm = (ExpressionTerm)ParseSubExpressions(chain.Right);
                expressionTerm.Function = chain.Left.ToString();
                Parse(element, expressionTerm);
            }
        }
コード例 #6
0
        public static bool ParseParent(Element element, ExpressionTerm expressionPart)
        {
            if (expressionPart.IsValidFunctionByName("Parent.Name") == true)
            {
                EnsureParent(element);
                element.Parent.Name = expressionPart.Value;
                return(true);
            }
            else if (expressionPart.IsValidFunctionByName("Parent.Text") == true)
            {
                EnsureParent(element);
                element.Parent.Text              = expressionPart.Value;
                element.Parent.TextFunction      = expressionPart.FunctionArgument;
                element.Parent.TextContainsEqual = expressionPart.ExpressionBooleanCondition;
                return(true);
            }
            else if (expressionPart.IsValidFunctionByRegex("Parent.Attribute(.*)\\.Contains") == true)
            {
                EnsureParent(element);
                element.Parent.Attributes.Add(new Model.Attribute(expressionPart.FunctionArgument)
                {
                    Text = expressionPart.Value, Equal = expressionPart.ExpressionBooleanCondition
                });
                return(true);
            }
            else if (expressionPart.IsValidFunctionByRegex("Parent.Attribute(.*)\\.Text") == true)
            {
                EnsureParent(element);
                element.Parent.Attributes.Add(new Model.Attribute(expressionPart.FunctionArgument)
                {
                    Text = expressionPart.Value, ExactMatch = true
                });
                return(true);
            }
            else if (expressionPart.IsValidFunctionByName("Parent.Position") == true)
            {
                element.Parent.Position = Int32.Parse(expressionPart.Value);
                return(true);
            }

            return(false);
        }
コード例 #7
0
        public static bool ParseSiblings(Element element, ExpressionTerm expressionPart)
        {
            if (expressionPart.IsValidFunctionByName(".FollowingSibling.Name") == true)
            {
                element.Siblings.Add(new Sibling()
                {
                    Name = expressionPart.Value
                });
                return(true);
            }
            else if (expressionPart.IsValidFunctionByName(".PrecedingSibling.Name") == true)
            {
                element.Siblings.Add(new Sibling()
                {
                    Name = expressionPart.Value, Preceding = true
                });
                return(true);
            }

            return(false);
        }
コード例 #8
0
        public static bool ParseRelatives(Element element, ExpressionTerm expressionPart)
        {
            if (expressionPart.IsValidFunctionByName(".Descendant") == true)
            {
                element.Relatives.Add(new Relative()
                {
                    Descendant = true, Name = expressionPart.Value
                });
                return(true);
            }

            if (expressionPart.IsValidFunctionByName(".Ancestor") == true)
            {
                element.Relatives.Add(new Relative()
                {
                    Descendant = false, Name = expressionPart.Value
                });
                return(true);
            }

            return(false);
        }