YamlDotNet.RepresentationModel.YamlNode.ParseNode C# (CSharp) Method

ParseNode() static private method

Parses the node represented by the next event in parser.
static private ParseNode ( IParser parser, DocumentLoadingState state ) : YamlNode
parser IParser
state DocumentLoadingState
return YamlNode
        internal static YamlNode ParseNode(IParser parser, DocumentLoadingState state)
        {
            if (parser.Accept<Scalar>())
            {
                return new YamlScalarNode(parser, state);
            }

            if (parser.Accept<SequenceStart>())
            {
                return new YamlSequenceNode(parser, state);
            }

            if (parser.Accept<MappingStart>())
            {
                return new YamlMappingNode(parser, state);
            }

            if (parser.Accept<AnchorAlias>())
            {
                var alias = parser.Expect<AnchorAlias>();
                return state.GetNode(alias.Value, false, alias.Start, alias.End) ?? new YamlAliasNode(alias.Value);
            }

            throw new ArgumentException("The current event is of an unsupported type.", "events");
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlDocument"/> class.
        /// </summary>
        /// <param name="events">The events.</param>
        internal YamlDocument(EventReader events)
        {
            DocumentLoadingState state = new DocumentLoadingState();

            events.Expect <DocumentStart>();

            while (!events.Accept <DocumentEnd>())
            {
                Debug.Assert(RootNode == null);
                RootNode = YamlNode.ParseNode(events, state);

                if (RootNode is YamlAliasNode)
                {
                    throw new YamlException();
                }
            }

            state.ResolveAliases();

#if DEBUG
            foreach (var node in AllNodes)
            {
                if (node is YamlAliasNode)
                {
                    throw new InvalidOperationException("Error in alias resolution.");
                }
            }
#endif

            events.Expect <DocumentEnd>();
        }
All Usage Examples Of YamlDotNet.RepresentationModel.YamlNode::ParseNode