public static void Serialize(Document document, TextWriter writer, SerializerSettings settings = null)
        {
            var index = DirectiveHandlerUtility.GetHandlersDictionaryByType(settings?.CustomHandlers);

            foreach (ILine line in document.Lines)
            {
                if (line is Directive)
                {
                    writer.WriteLine(index[line.GetType()].GetString(line as Directive, settings?.ShortenDirectives == true));                     // TODO: harden
                }
                else if (line is SongLine)
                {
                    // writer.WriteLine(line.ToString()); // TODO: fix
                    Write(writer, line as SongLine);
                }
                else if (line is TabLine)
                {
                    writer.WriteLine((line as TabLine).Text);
                }
                else
                {
                    throw new ArgumentException("unknown line type");
                }
            }
        }
예제 #2
0
 internal Parser(TextReader textReader, IEnumerable <DirectiveHandler> customHandlers)
 {
     _textReader       = textReader;
     _directiveParsers = DirectiveHandlerUtility.GetHandlersDictionaryByName(customHandlers);
 }