Example #1
0
        private static EventType GetEventType(IParsingEvent @event)
        {
            if (@event is IAnchorAlias)
            {
                return EventType.YAML_ALIAS_EVENT;
            }

            if (@event is IDocumentEnd)
            {
                return EventType.YAML_DOCUMENT_END_EVENT;
            }

            if (@event is IDocumentStart)
            {
                return EventType.YAML_DOCUMENT_START_EVENT;
            }

            if (@event is IMappingEnd)
            {
                return EventType.YAML_MAPPING_END_EVENT;
            }

            if (@event is IMappingStart)
            {
                return EventType.YAML_MAPPING_START_EVENT;
            }

            if (@event is IScalar)
            {
                return EventType.YAML_SCALAR_EVENT;
            }

            if (@event is ISequenceEnd)
            {
                return EventType.YAML_SEQUENCE_END_EVENT;
            }

            if (@event is ISequenceStart)
            {
                return EventType.YAML_SEQUENCE_START_EVENT;
            }

            if (@event is IStreamEnd)
            {
                return EventType.YAML_STREAM_END_EVENT;
            }

            if (@event is IStreamStart)
            {
                return EventType.YAML_STREAM_START_EVENT;
            }

            throw new ArgumentException("The specified event is of the wrong type.");
        }
Example #2
0
        /// <summary>
        /// Expect a node.
        /// </summary>
        private void EmitNode(IParsingEvent evt, bool isRoot, bool isMapping, bool isSimpleKey)
        {
            isRootContext = isRoot;
            isMappingContext = isMapping;
            isSimpleKeyContext = isSimpleKey;

            var eventType = GetEventType(evt);
            switch (eventType)
            {
                case EventType.YAML_ALIAS_EVENT:
                    EmitAlias();
                    break;

                case EventType.YAML_SCALAR_EVENT:
                    EmitScalar(evt);
                    break;

                case EventType.YAML_SEQUENCE_START_EVENT:
                    EmitSequenceStart(evt);
                    break;

                case EventType.YAML_MAPPING_START_EVENT:
                    EmitMappingStart(evt);
                    break;

                default:
                    throw new YamlException(string.Format("Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, got {0}", eventType));
            }
        }