Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlSequenceNode"/> class.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        internal YamlSequenceNode(EventReader events, DocumentLoadingState state)
        {
            SequenceStart sequence = events.Expect <SequenceStart>();

            Load(sequence, state);
            Style = sequence.Style;

            bool hasUnresolvedAliases = false;

            while (!events.Accept <SequenceEnd>())
            {
                YamlNode child = ParseNode(events, state);
                children.Add(child);
                hasUnresolvedAliases |= child is YamlAliasNode;
            }

            if (hasUnresolvedAliases)
            {
                state.AddNodeWithUnresolvedAliases(this);
            }
#if DEBUG
            else
            {
                foreach (var child in children)
                {
                    if (child is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                }
            }
#endif

            events.Expect <SequenceEnd>();
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        internal YamlMappingNode(EventReader events, DocumentLoadingState state)
        {
            MappingStart mapping = events.Expect <MappingStart>();

            Load(mapping, state);
            Style = mapping.Style;

            bool hasUnresolvedAliases = false;

            while (!events.Accept <MappingEnd>())
            {
                YamlNode key   = ParseNode(events, state);
                YamlNode value = ParseNode(events, state);

                try
                {
                    children.Add(key, value);
                }
                catch (ArgumentException err)
                {
                    throw new YamlException(key.Start, key.End, "Duplicate key", err);
                }

                hasUnresolvedAliases |= key is YamlAliasNode || value is YamlAliasNode;
            }

            if (hasUnresolvedAliases)
            {
                state.AddNodeWithUnresolvedAliases(this);
            }
#if DEBUG
            else
            {
                foreach (var child in children)
                {
                    if (child.Key is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                    if (child.Value is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                }
            }
#endif

            events.Expect <MappingEnd>();
        }