Пример #1
0
        public Type TypeFromTag(string tag)
        {
            Type type;

            tag = YamlNode.ExpandTag(tag);
            if (!aliasTagToType.TryGetValue(tag, out type))
            {
                if (types.ContainsKey(tag))
                {
                    return(types[tag][0].GetTypeOfValue());
                }
            }

            return(type);
        }
Пример #2
0
        /// <summary>
        /// Decode <paramref name="text"/> 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);
        }