Exemplo n.º 1
0
 private static string TypeNameToYamlTag(Type type)
 {
     /*
      * if ( TypeUtils.GetType(type.FullName) == null ) {
      *  throw new ArgumentException(
      *      "Can not serialize (non public?) type '{0}'.".DoFormat(type.FullName));
      * }
      */
     if (type == typeof(int))
     {
         return(YamlNode.ExpandTag("!!int"));
     }
     if (type == typeof(string))
     {
         return(YamlNode.ExpandTag("!!str"));
     }
     if (type == typeof(Double))
     {
         return(YamlNode.ExpandTag("!!float"));
     }
     if (type == typeof(bool))
     {
         return(YamlNode.ExpandTag("!!bool"));
     }
     if (type == typeof(object[]))
     {
         return(YamlNode.ExpandTag("!!seq"));
     }
     return("!" + type.FullName);
 }
Exemplo n.º 2
0
        private string TypeNameToYamlTag(Type type)
        {
            if (type == typeof(int))
            {
                return(YamlNode.ExpandTag("!!int"));
            }
            if (type == typeof(string))
            {
                return(YamlNode.ExpandTag("!!str"));
            }
            if (type == typeof(Double))
            {
                return(YamlNode.ExpandTag("!!float"));
            }
            if (type == typeof(bool))
            {
                return(YamlNode.ExpandTag("!!bool"));
            }
            if (type == typeof(object[]))
            {
                return(YamlNode.ExpandTag("!!seq"));
            }

            return(config.TagResolver.TagFromType(type));
        }
Exemplo n.º 3
0
        private YamlScalar MapKey(string key)
        {
            var node = (YamlScalar)key;

            node.Properties["expectedTag"] = YamlNode.ExpandTag("!!str");
            node.Properties["plainText"]   = "true";
            return(node);
        }
Exemplo n.º 4
0
 public Type TypeFromTag(string tag)
 {
     tag = YamlNode.ExpandTag(tag);
     if (types.ContainsKey(tag))
     {
         return(types[tag][0].GetTypeOfValue());
     }
     return(null);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Decode <paramref name="node"/> and returns actual value in C# object.
        /// </summary>
        /// <param name="node">Node to be decoded.</param>
        /// <param name="obj">Decoded value.</param>
        /// <returns>True if decoded successfully.</returns>
        public bool Decode(YamlScalar node, out object obj)
        {
            obj = null;
            if (node.Tag == null || node.Value == null)
            {
                return(false);
            }
            var tag = YamlNode.ExpandTag(node.Tag);

            if (!types.ContainsKey(tag))
            {
                return(false);
            }
            foreach (var rule in types[tag])
            {
                var m = rule.Pattern.Match(node.Value);
                if (m.Success)
                {
                    obj = rule.Decode(m);
                    return(true);
                }
            }
            return(false);
        }