public static object ToYamlProperties(object self, [NotNull] RubyRepresenter /*!*/ rep) { var map = new Dictionary <object, object>(); rep.AddYamlProperties(map, self, true); return(rep.Map(self, map)); }
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); } }
private static IEnumerable <KeyValuePair <string, object> > /*!*/ EnumerateAttributes(RubyContext /*!*/ context, Hash /*!*/ mapping) { foreach (var entry in mapping) { yield return(new KeyValuePair <string, object>("@" + RubyRepresenter.ConvertToFieldName(context, entry.Key), entry.Value)); } }
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); } }
public static object ToYamlProperties(object self, [NotNull] RubyRepresenter /*!*/ rep) { Hash map = new Hash(rep.Context); RubyRepresenter.AddYamlProperties(rep.Context, self, map); return(rep.Map(self, map)); }
public static Node /*!*/ ToYaml(RubyRegex /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar( rep.GetTagUri(self), self.Inspect().ToAsciiString(), ScalarQuotingStyle.None )); }
public static Node ToYamlNode(Exception /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { Hash map = new Hash(rep.Context); map.Add(MutableString.Create("message"), _Message.Target(_Message, rep.Context, self)); RubyRepresenter.AddYamlProperties(rep.Context, self, map); return(rep.Map(self, map)); }
public static Node /*!*/ ToYaml(RubyRegex /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar( rep.GetTagUri(self), self.Inspect().ToAsciiString(rep.Context.RubyOptions.Compatibility < RubyCompatibility.Ruby19), ScalarQuotingStyle.None )); }
public static Node /*!*/ ToYaml(RubySymbol /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar( // TODO: we should use RubySymbol but that would require ResolverScanner to recognize symbols in order not to emit a tag Tags.Str, SymbolOps.Inspect(rep.Context, self).ToAsciiString(), ScalarQuotingStyle.None )); }
public static Node ToYaml(object self, [NotNull] RubyRepresenter /*!*/ rep) { Hash map = new Hash(rep.Context); map.Add(MutableString.Create("begin"), _Begin.Target(_Begin, rep.Context, self)); map.Add(MutableString.Create("end"), _End.Target(_End, rep.Context, self)); map.Add(MutableString.Create("excl"), _ExcludeEnd.Target(_ExcludeEnd, rep.Context, self)); RubyRepresenter.AddYamlProperties(rep.Context, self, map); return(rep.Map(self, map)); }
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)); } }
public static Node /*!*/ ToYaml(RubyTime /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { TimeSpan offset = self.GetCurrentZoneOffset(); long fractional = self.Microseconds; string value = String.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd HH:mm:ss}" + (fractional == 0 ? "" : ".{1:D6}") + (self.Kind == DateTimeKind.Utc ? " Z" : " {2}{3:D2}:{4:D2}"), self.DateTime, fractional, offset.Hours >= 0 ? "+" : "", offset.Hours, offset.Minutes ); return(rep.Scalar(rep.GetTagUri(self), value, ScalarQuotingStyle.None)); }
public static Node /*!*/ ToYamlNode(RubyStruct /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { var fieldNames = self.GetNames(); var fields = new Dictionary <Node, Node>(fieldNames.Count); for (int i = 0; i < fieldNames.Count; i++) { fields[rep.Scalar(null, fieldNames[i], ScalarQuotingStyle.None)] = rep.RepresentItem(self.Values[i]); } var map = new Dictionary <object, object>(); rep.AddYamlProperties(map, self, false); return(rep.Map(fields, rep.GetTagUri(self), map, FlowStyle.Block)); }
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); } }
public static Node /*!*/ ToYaml(double self, [NotNull] RubyRepresenter /*!*/ rep) { if (Double.IsNaN(self)) { return(rep.Scalar(Tags.Float, ".NaN", ScalarQuotingStyle.None)); } if (Double.IsNegativeInfinity(self)) { return(rep.Scalar(Tags.Float, "-.Inf", ScalarQuotingStyle.None)); } if (Double.IsPositiveInfinity(self)) { return(rep.Scalar(Tags.Float, ".Inf", ScalarQuotingStyle.None)); } return(rep.Scalar(Tags.Float, ClrFloat.ToS(rep.Context, self).ToString(), ScalarQuotingStyle.None)); }
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); }
public static Node /*!*/ ToYaml(UnaryOpStorage /*!*/ beginStorage, UnaryOpStorage /*!*/ endStorage, UnaryOpStorage /*!*/ exclStorage, Range /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { var begin = beginStorage.GetCallSite("begin"); var end = endStorage.GetCallSite("end"); var map = new Dictionary <object, object>(); rep.AddYamlProperties(map, self, false); return(rep.Map( new Dictionary <Node, Node> { { rep.Scalar(null, "begin", ScalarQuotingStyle.None), rep.RepresentItem(begin.Target(begin, self)) }, { rep.Scalar(null, "end", ScalarQuotingStyle.None), rep.RepresentItem(end.Target(end, self)) }, { rep.Scalar(null, "excl", ScalarQuotingStyle.None), rep.Scalar(self.ExcludeEnd) }, }, rep.GetTagUri(self), map, FlowStyle.Block )); }
public static Node ToYamlNode(RubyStruct /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { RubyContext context = self.Class.Context; RubyArray members = _Members.Target(_Members, context, self); RubyArray values = _Values.Target(_Values, context, self); if (members.Count != values.Count) { throw new ArgumentException("Struct values and members returned arrays of different lengths"); } Hash map = new Hash(self.Class.Context); for (int i = 0; i < members.Count; i++) { IDictionaryOps.SetElement(context, map, members[i], values[i]); } RubyRepresenter.AddYamlProperties(context, self, map); return(rep.Map(self, map)); }
public static Node /*!*/ ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { if (!self.IsEmpty && ContainsBinaryData(self)) { return(rep.BaseCreateNode(self.ToByteArray())); } Debug.Assert(self.IsAscii()); string str = self.ToString(); ScalarQuotingStyle style = ScalarQuotingStyle.None; if (str.StartsWith(":", StringComparison.Ordinal)) { style = ScalarQuotingStyle.Double; } else { style = rep.GetYamlStyle(self); } var tag = rep.GetTagUri(self, Tags.Str, typeof(MutableString)); IList instanceVariableNames = rep.ToYamlProperties(self); if (instanceVariableNames.Count == 0) { return(rep.Scalar(tag, str, style)); } var map = new Dictionary <object, object>(); rep.AddYamlProperties(map, self, instanceVariableNames, false); return(rep.Map( new Dictionary <Node, Node> { { rep.Scalar(null, "str", style), rep.Scalar(null, str, style) } }, tag, map, FlowStyle.Block )); }
public static Node /*!*/ ToYaml(double self, [NotNull] RubyRepresenter /*!*/ rep) { MutableString str = RubySites.ToS(rep.Context, self); if (str != null) { if (str.Equals("Infinity")) { str = MutableString.Create(".Inf"); } else if (str.Equals("-Infinity")) { str = MutableString.Create("-.Inf"); } else if (str.Equals("NaN")) { str = MutableString.Create(".NaN"); } } return(rep.Scalar(self, str)); }
public static Node ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { if (RubyOps.IsTrue(_IsBinaryData.Target(_IsBinaryData, rep.Context, self))) { return(rep.BaseCreateNode(self.ConvertToBytes())); } string str = self.ConvertToString(); RubyArray props = RubyRepresenter.ToYamlProperties(rep.Context, self); if (props.Count == 0) { MutableString taguri = RubyRepresenter.TagUri(rep.Context, self); char style = (char)0; if (str.StartsWith(":")) { style = '"'; } else { MutableString styleStr = RubyRepresenter.ToYamlStyle(rep.Context, self) as MutableString; if (styleStr != null && styleStr.Length > 0) { style = styleStr.GetChar(0); } } return(rep.Scalar(taguri != null ? taguri.ConvertToString() : "", str, style)); } Hash map = new Hash(rep.Context); map.Add(MutableString.Create("str"), str); RubyRepresenter.AddYamlProperties(rep.Context, self, map, props); return(rep.Map(self, map)); }
public static void Add(YamlCallSiteStorage/*!*/ siteStorage, MappingNode/*!*/ self, object key, object value) { RubyRepresenter rep = new RubyRepresenter(siteStorage); self.Nodes.Add(rep.RepresentItem(key), rep.RepresentItem(value)); }
public static Node /*!*/ ToYaml([NotNull] BigInteger self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar(Tags.Bignum, self.ToString(CultureInfo.InvariantCulture), ScalarQuotingStyle.None)); }
public static Node /*!*/ ToYaml(int self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar(Tags.Int, self.ToString(), ScalarQuotingStyle.None)); }
public static Node ToYamlNode(UnaryOpStorage /*!*/ messageStorage, Exception /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { var site = messageStorage.GetCallSite("message", 0); var map = new Dictionary <object, object>(); rep.AddYamlProperties(map, self, false); return(rep.Map( new Dictionary <Node, Node> { { rep.Scalar(null, "message", ScalarQuotingStyle.None), rep.RepresentItem(site.Target(site, self)) } }, rep.GetTagUri(self), map, FlowStyle.Block )); }
public static void Add(YamlCallSiteStorage/*!*/ siteStorage, SequenceNode/*!*/ self, object value) { RubyRepresenter rep = new RubyRepresenter(siteStorage); self.Nodes.Add(rep.RepresentItem(value)); }
public static int GetLevel(RubyRepresenter/*!*/ self) { return self.Level; }
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; } }
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 Node /*!*/ ToYaml(ConversionStorage <MutableString> /*!*/ tosConversion, bool self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar(self)); }
public static int SetLevel(RubyRepresenter/*!*/ self, [DefaultProtocol]int level) { return self.Level = level; }
public static Node /*!*/ ToYaml(ConversionStorage <MutableString> /*!*/ tosConversion, object /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { string value = Protocols.ConvertToString(tosConversion, self).ToString(); return(rep.Scalar(rep.GetTagUri(self), value, ScalarQuotingStyle.None)); }
public static Node ToYamlNode(RubyContext /*!*/ context, RubyArray /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Sequence( rep.GetTagUri(self, Tags.Seq, typeof(RubyArray)), self, rep.GetYamlStyle(self) != ScalarQuotingStyle.None ? FlowStyle.Inline : FlowStyle.Block )); }
internal Out(RubyRepresenter/*!*/ representer) { Assert.NotNull(representer); _representer = representer; }
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; } }
public static Node /*!*/ ToYaml(object self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Scalar(Tags.Null, null, ScalarQuotingStyle.None)); }
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; } }
public static Node ToYamlNode(RubyContext /*!*/ context, object self, RubyRepresenter rep) { throw RubyExceptions.CreateTypeError("can't dump anonymous class " + context.GetClassDisplayName(self)); }
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; } }
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; }
public static Node/*!*/ Map(RubyContext/*!*/ context, [NotNull]BlockParam/*!*/ block, RubyRepresenter/*!*/ self, [DefaultProtocol]MutableString taguri, object to_yaml_style) { var map = new Dictionary<object, object>(); object blockResult; block.Yield(map, out blockResult); return self.Map(taguri, to_yaml_style ?? false, map); }
public static Node ToYamlNode(RubyContext/*!*/ context, object self, RubyRepresenter rep) { throw RubyExceptions.CreateTypeError("can't dump anonymous class " + RubyUtils.GetClassName(context, self)); }
public static Node ToYamlNode(Hash /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { return(rep.Map(self, self)); }