Beispiel #1
0
        internal static object DumpAll(RubyContext /*!*/ context, [NotNull] IEnumerable objs, [Optional] RubyIO io)
        {
            TextWriter writer;

            if (io != null)
            {
                writer = new RubyIOWriter(io);
            }
            else
            {
                writer = new MutableStringWriter();
            }
            YamlOptions cfg = YamlOptions.DefaultOptions;

            using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
                RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                foreach (object obj in objs)
                {
                    r.Represent(obj);
                }
            }
            if (null != io)
            {
                return(io);
            }
            else
            {
                return(((MutableStringWriter)writer).String);
            }
        }
Beispiel #2
0
        internal static object DumpAll(RubyRepresenter /*!*/ rep, IEnumerable /*!*/ objs, RubyIO io)
        {
            TextWriter writer;

            if (io != null)
            {
                writer = new RubyIOWriter(io);
            }
            else
            {
                // the output is ascii:
                writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.Binary));
            }

            YamlOptions cfg = YamlOptions.DefaultOptions;
            Serializer  s   = new Serializer(writer, cfg);

            foreach (object obj in objs)
            {
                s.Serialize(rep.Represent(obj));
                rep.ForgetObjects();
            }
            s.Close();

            if (io != null)
            {
                return(io);
            }
            else
            {
                return(((MutableStringWriter)writer).String);
            }
        }
 public static object ToYaml(object self, [NotNull] RubyRepresenter /*!*/ emitter)
 {
     if (emitter.Level > 0)
     {
         // return a node:
         return(emitter.Represent(self));
     }
     else
     {
         // return a string:
         return(RubyYaml.DumpAll(emitter, new object[] { self }, null));
     }
 }
Beispiel #4
0
        internal static object DumpAll(RubyRepresenter/*!*/ rep, IEnumerable/*!*/ objs, RubyIO io) {
            TextWriter writer;
            if (io != null) {
                writer = new RubyIOWriter(io);
            } else {
                // the output is ascii:
                writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.Binary));
            }

            YamlOptions cfg = YamlOptions.DefaultOptions;
            Serializer s = new Serializer(writer, cfg);
            foreach (object obj in objs) {
                s.Serialize(rep.Represent(obj));
                rep.ForgetObjects();
            }
            s.Close();

            if (io != null) {
                return io;
            } else {
                return ((MutableStringWriter)writer).String;
            }
        }
Beispiel #5
0
 internal static object DumpAll(RubyContext/*!*/ context, [NotNull]IEnumerable objs, [Optional]RubyIO io) {
     TextWriter writer;
     if (io != null) {
         writer = new RubyIOWriter(io);
     } else {
         writer = new MutableStringWriter();
     }
     YamlOptions cfg = YamlOptions.DefaultOptions;
     using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
         RubyRepresenter r = new RubyRepresenter(context, s, cfg);
         foreach (object obj in objs) {
             r.Represent(obj);
         }
     }
     if (null != io) {
         return io;
     } else {
         return ((MutableStringWriter)writer).String;
     }
 }