예제 #1
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);
            }
        }
예제 #2
0
        public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
            : base(serializer, opts) {
            _context = context;
            _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", VisibilityContext.AllVisible).Info;

             _TagUri =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "taguri", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlStyle =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_style", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlNode =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_node", RubyCallSignature.WithImplicitSelf(1))
            );

            _ToYaml =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlProperties = 
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_properties", RubyCallSignature.WithImplicitSelf(0))
            );
        }
예제 #3
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);
            }
        }
예제 #4
0
 public Serializer(IEmitter emitter, YamlOptions opts) {
     _emitter = emitter;
     _useExplicitStart = opts.ExplicitStart;
     _useExplicitEnd = opts.ExplicitEnd;
     if (opts.UseVersion) {
         _useVersion = opts.Version;
     }
     _explicitTypes = opts.ExplicitTypes;
     _useTags = opts.UseHeader;
     _anchorTemplate = opts.AnchorFormat ?? "id{0:000}";
     _emitter.Emit(StreamStartEvent.Instance);
 }
예제 #5
0
        public Serializer(Emitter/*!*/ emitter, YamlOptions/*!*/ opts) {
            ContractUtils.RequiresNotNull(emitter, "emitter");

            _emitter = emitter;
            _useExplicitStart = opts.ExplicitStart;
            _useExplicitEnd = opts.ExplicitEnd;
            if (opts.UseVersion) {
                _useVersion = opts.Version;
            }
            _anchorTemplate = opts.AnchorFormat ?? "id{0:000}";
            _emitter.Emit(StreamStartEvent.Instance);
        }
예제 #6
0
 public Serializer(IEmitter emitter, YamlOptions opts)
 {
     _emitter          = emitter;
     _useExplicitStart = opts.ExplicitStart;
     _useExplicitEnd   = opts.ExplicitEnd;
     if (opts.UseVersion)
     {
         _useVersion = opts.Version;
     }
     _explicitTypes  = opts.ExplicitTypes;
     _useTags        = opts.UseHeader;
     _anchorTemplate = opts.AnchorFormat ?? "id{0:000}";
     _emitter.Emit(StreamStartEvent.Instance);
 }
예제 #7
0
        public Serializer(Emitter /*!*/ emitter, YamlOptions /*!*/ opts)
        {
            ContractUtils.RequiresNotNull(emitter, "emitter");

            _emitter          = emitter;
            _useExplicitStart = opts.ExplicitStart;
            _useExplicitEnd   = opts.ExplicitEnd;
            if (opts.UseVersion)
            {
                _useVersion = opts.Version;
            }
            _anchorTemplate = opts.AnchorFormat ?? "id{0:000}";
            _emitter.Emit(StreamStartEvent.Instance);
        }
예제 #8
0
파일: Emitter.cs 프로젝트: atczyc/ironruby
        public Emitter(TextWriter/*!*/ stream, YamlOptions opts) {
            ContractUtils.RequiresNotNull(stream, "stream");

            _stream = stream;
            _options = opts;
            canonical = _options.Canonical;
            int propIndent = _options.Indent;
            if (propIndent>=2 && propIndent<10) {
                _bestIndent = propIndent;
            }
            int propWidth = _options.BestWidth;
            if (propWidth != 0 && propWidth > (_bestIndent*2)) {
                _bestWidth = propWidth;
            }
        }
예제 #9
0
파일: Emitter.cs 프로젝트: jschementi/iron
        public Emitter(TextWriter/*!*/ writer, YamlOptions/*!*/ opts) {
            ContractUtils.RequiresNotNull(writer, "writer");
            ContractUtils.RequiresNotNull(opts, "opts");

            _writer = writer;
            _options = opts;
            _canonical = _options.Canonical;
            int propIndent = _options.Indent;
            if (propIndent>=2 && propIndent<10) {
                _bestIndent = propIndent;
            }
            int propWidth = _options.BestWidth;
            if (propWidth != 0 && propWidth > (_bestIndent*2)) {
                _bestWidth = propWidth;
            }
        }
예제 #10
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);
            }
        }
예제 #11
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);
        }
예제 #12
0
 public Representer(ISerializer serializer, YamlOptions opts)
     : this(serializer, opts.UseDouble ? '"' : (opts.UseSingle ? '\'' : '\0'))
 {
 }
예제 #13
0
 public RubyRepresenter(RubyContext /*!*/ context, ISerializer /*!*/ serializer, YamlOptions /*!*/ opts)
     : base(serializer, opts)
 {
     _context            = context;
     _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", false);
 }
예제 #14
0
 public Serializer(TextWriter /*!*/ writer, YamlOptions /*!*/ opts)
     : this(new Emitter(writer, opts), opts)
 {
 }
예제 #15
0
 public Serializer(TextWriter/*!*/ writer, YamlOptions/*!*/ opts)
     : this(new Emitter(writer, opts), opts) {
 }
예제 #16
0
 public Parser(Scanner scanner, YamlOptions opts)
     : this(scanner, opts.Version)
 {
 }
예제 #17
0
 public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
     : base(serializer, opts) {
     _context = context;
     _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", RubyClass.IgnoreVisibility).Info;
 }
예제 #18
0
 public Representer(Serializer/*!*/ serializer, YamlOptions opts)
     : this(serializer, opts.UseDouble ? '"' : (opts.UseSingle ? '\'' : '\0')) {
 }
예제 #19
0
파일: Emitter.cs 프로젝트: bclubb/ironruby
 public Emitter(TextWriter stream, YamlOptions opts) {
     _stream = stream;
     _options = opts;
     canonical = _options.Canonical;
     int propIndent = _options.Indent;
     if (propIndent>=2 && propIndent<10) {
         _bestIndent = propIndent;
     }
     int propWidth = _options.BestWidth;
     if (propWidth != 0 && propWidth > (_bestIndent*2)) {
         _bestWidth = propWidth;
     }
 }
예제 #20
0
 public RubyRepresenter(RubyContext/*!*/ context, ISerializer/*!*/ serializer, YamlOptions/*!*/ opts)
     : base(serializer, opts) {
     _context = context;
     _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", false);
 }