Exemple #1
0
 public SharpMetaNodeRow(SharpMetaNodeRow source)
 {
     Index          = source.Index;
     Path           = source.Path;
     NodeType       = source.NodeType;
     ValueType      = source.ValueType;
     AdditionalInfo = source.AdditionalInfo.ToDictionary(x => x.Key, x => new SharpValue(x.Value));
     QueryPath      = source.QueryPath.ToDictionary(x => x.Key,
                                                    x => new KeyValuePair <string, string>(x.Value.Key, x.Value.Value));
 }
        public bool ParseRowLine(string line, out SharpRow result)
        {
            result = null;
            line   = line.Trim();
            if (string.IsNullOrEmpty(line))
            {
                return(false);
            }

            if (line.StartsWith("#!"))
            {
                var param = new SharpMetaParameterRow(line);
                if (param.Key.ToLower() == "package" && _nodes != null)
                {
                    _nodes.SetCurrentPackage(param.Value.ToString());
                }
                result = param;
                return(true);
            }

            if (line.StartsWith("#"))
            {
                result = new SharpMetaCommentRow {
                    Value = line.Substring(1)
                };
                return(true);
            }

            var metaNode = new SharpMetaNodeRow(line, _lastFullPath);

            if (line.StartsWith("$"))
            {
                var schemaNode = metaNode.CreateNode();

                if (metaNode.Index == -1)
                {
                    _nodes.Add(schemaNode);
                }
                else
                {
                    _nodes.Insert(schemaNode);
                }

                return(false);
            }

            bool isValueNode = metaNode.IsValueNode;

            if (!isValueNode)
            {
                _lastFullPath = metaNode.Path;
            }

            if (_nodes == null)
            {
                result = metaNode;
                return(true);
            }

            var node = _nodes.GetNode(metaNode.Path);

            if (node != null)
            {
                result = metaNode.CreateNodeRow(node);
                return(true);
            }

            node = metaNode.CreateNode();
            _nodes.Add(node);
            result = metaNode.CreateNodeRow(node);
            return(true);
        }