Exemple #1
0
        private List <FieldTree> CreateFieldTree(Queue <Token> tokens, FieldTree parent)
        {
            List <FieldTree> fields = new List <FieldTree>();

            while (tokens.Count > 0)
            {
                Token     token = tokens.Dequeue();
                FieldTree field = new FieldTree(token.Value);

                if (CanAddParent(token))
                {
                    fields.Add(parent);
                    return(fields);
                }

                if (field.CanStep(token, parent))
                {
                    continue;
                }

                parent.AddNodes(CreateFieldTree(tokens, field));

                if (parent.IsRootNode())
                {
                    fields.Add(field);
                }
            }

            return(fields);
        }
Exemple #2
0
        public string ParseValues(object[] values)
        {
            if (values == null || values.Length == 0)
            {
                return(string.Empty);
            }

            var rawText = string.Join(",", values);

            if (string.IsNullOrEmpty(rawText))
            {
                return(string.Empty);
            }

            var root      = FieldTree.CreateRootNode();
            var tokens    = Tokenize(rawText);
            var fieldTree = CreateFieldTree(tokens, root);

            if (fieldTree.Count == 1)
            {
                return(fieldTree[0].HasChilds() ? $"new ( {fieldTree[0].ToString()})" : fieldTree[0].ToString());
            }

            return($"new ({string.Join(", ", fieldTree.Select(s => s.ToString()))})");
        }
Exemple #3
0
        public bool CanStep(Token token, FieldTree parent)
        {
            if (token.Type == TokenType.BeginBrack)
            {
                parent.Type = FieldType.Collection;
            }

            return(token.Type == TokenType.BeginBrack || token.Type == TokenType.BeginParen);
        }