Ejemplo n.º 1
0
 private static object ConvertStructure(IParser parser)
 {
     if (parser.CheckEvent<Events.Scalar>())
     {
         var scalarEvent = (Events.Scalar)parser.GetEvent();
         return !string.IsNullOrEmpty(scalarEvent.Tag) ||
                !string.IsNullOrEmpty(scalarEvent.Anchor) ||
                !string.IsNullOrEmpty(scalarEvent.Value)
                    ? (object) true
                    : null;
     }
     if (parser.CheckEvent<Events.SequenceStart>())
     {
         parser.GetEvent();
         var list = new List<object>();
         while (!parser.CheckEvent<Events.SequenceEnd>())
             list.Add(ConvertStructure(parser));
         parser.GetEvent();
         return new EquatableList<object>(list);
     }
     if (parser.CheckEvent<Events.MappingStart>())
     {
         parser.GetEvent();
         var map = new List<object>();
         while (!parser.CheckEvent<Events.MappingEnd>())
         {
             var key = ConvertStructure(parser);
             var value = ConvertStructure(parser);
             map.Add(Tuple.Create(key, value));
         }
         parser.GetEvent();
         return new EquatableList<object>(map);
     }
     if (parser.CheckEvent<Events.Alias>())
     {
         parser.GetEvent();
         return "*";
     }
     parser.CheckEvent();
     return "?";
 }