Example #1
0
        protected override void VisitChildren(YamlSequenceNode sequence)
        {
            foreach (var node in sequence.Children)
            {
                this.EnterContext(index.ToString());

                var visitor = new ContextAwareVisitor(context);
                node.Accept(visitor);
                this.items.AddRange(visitor.Items);

                this.ExitContext();
                index++;
            }
        }
        protected override void VisitChildren(YamlSequenceNode sequence)
        {
            foreach (var node in sequence.Children)
            {
                this.EnterContext(index.ToString());

                var visitor = new ContextAwareVisitor(context);
                node.Accept(visitor);
                this.items.AddRange(visitor.Items);

                this.ExitContext();
                index++;
            }
        }
        public IDictionary<string, string> Parse(Stream input)
        {
            IDictionary<string, string> data = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            var visitor = new ContextAwareVisitor();

            var yamlStream = new YamlStream();

            using (var reader = new StreamReader(input))
            {
                yamlStream.Load(reader);

            }

            if (!yamlStream.Documents.Any())
            {
                return data;
            }

            yamlStream.Accept(visitor);

            foreach (var item in visitor.Items)
            {
                var key = item.Key;

                if (!string.IsNullOrEmpty(this.root))
                {
                    key = ConfigurationPath.Combine(this.root, key);
                }

                if (data.ContainsKey(key))
                {
                    throw new FormatException(string.Format("The key '{0}' is duplicated.", key));
                }
                data[key] = item.Value;
            }

            return data;
        }