Inheritance: System.IO.TextWriter
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        public static object QuickEmit(RubyContext /*!*/ context, BlockParam /*!*/ block, RubyModule /*!*/ self, object objectId, params object[] opts)
        {
            if (block == null)
            {
                throw RubyExceptions.NoBlockGiven();
            }
            MutableStringWriter writer = new MutableStringWriter();
            //We currently don't support serialization options, so we just ignore opts argument
            YamlOptions cfg = YamlOptions.DefaultOptions;

            using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
                RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                object          result;
                block.Yield(r, out result);
                s.Serialize(result as Node);
                return(writer.String);
            }
        }
Exemplo n.º 4
0
        public static object QuickEmit(YamlCallSiteStorage /*!*/ siteStorage, [NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self, object objectId, [NotNull] Hash /*!*/ opts)
        {
            // TODO: load from opts
            YamlOptions cfg = YamlOptions.DefaultOptions;

            MutableStringWriter writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.Binary));
            Serializer          s      = new Serializer(writer, cfg);
            RubyRepresenter     rep    = new RubyRepresenter(siteStorage);
            object result;

            if (block.Yield(new Syck.Out(rep), out result))
            {
                return(result);
            }

            s.Serialize(rep.ToNode(result));
            s.Close();

            return(writer.String);
        }
Exemplo n.º 5
0
        public static object QuickEmit(YamlCallSiteStorage/*!*/ siteStorage, [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, [NotNull]Hash/*!*/ opts) {
            // TODO: load from opts
            YamlOptions cfg = YamlOptions.DefaultOptions;
            
            MutableStringWriter writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.Binary));
            Serializer s = new Serializer(writer, cfg);
            RubyRepresenter rep = new RubyRepresenter(siteStorage);
            object result;
            
            if (block.Yield(new Syck.Out(rep), out result)) {
                return result;
            }

            s.Serialize(rep.ToNode(result));
            s.Close();

            return writer.String;
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
 public static object QuickEmit(RubyContext/*!*/ context, BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, params object[] opts) {
     if (block == null) {
         throw RubyExceptions.NoBlockGiven();
     }
     MutableStringWriter writer = new MutableStringWriter();
     //We currently don't support serialization options, so we just ignore opts argument
     YamlOptions cfg = YamlOptions.DefaultOptions;
     using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
         RubyRepresenter r = new RubyRepresenter(context, s, cfg);
         object result;
         block.Yield(r, out result);
         s.Serialize(result as Node);
         return writer.String;
     }
 }
Exemplo n.º 8
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;
     }
 }
Exemplo n.º 9
0
        public static MutableString QuickEmit(RubyContext/*!*/ context, [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, [NotNull]Hash/*!*/ opts) {
            YamlOptions cfg = YamlOptions.DefaultOptions;
            MutableStringWriter writer = new MutableStringWriter();
            Emitter emitter = new Emitter(writer, cfg);

            using (Serializer s = new Serializer(emitter, cfg)) {
                RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                object result;
                block.Yield(r, out result);
                s.Serialize(result as Node);

                return writer.String;
            }
        }
Exemplo n.º 10
0
        public static object QuickEmit(RubyContext/*!*/ context, [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, [NotNull]Hash/*!*/ opts) {
            YamlOptions cfg = YamlOptions.DefaultOptions;
            
            // TODO: encoding
            MutableStringWriter writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.UTF8));
            Emitter emitter = new Emitter(writer, cfg);

            using (Serializer s = new Serializer(emitter, cfg)) {
                RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                object result;

                if (block.Yield(r, out result)) {
                    return result;
                }

                s.Serialize(result as Node);
                return writer.String;
            }
        }