ToYamlProperties() private method

Dynamically calls to_yaml_properties on a given object. The method should return a list of instance variable names (Symbols or Strings) of the object that should be serialized into the output stream.
private ToYamlProperties ( object obj ) : IList
obj object
return IList
示例#1
0
        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
                       ));
        }
示例#2
0
        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));
        }
示例#3
0
 public static bool IsComplexYaml(RubyContext /*!*/ context, MutableString /*!*/ self)
 {
     return(RubyOps.IsTrue(RubyRepresenter.ToYamlStyle(context, self)) ||
            RubyRepresenter.ToYamlProperties(context, self).Count == 0 ||
            AFTER_NEWLINE(self.ConvertToString()));
 }