Beispiel #1
0
        public static TinyToken ToToken(object value)
        {
            if (value is TinyToken token)
            {
                return(token);
            }

            if (TinyValue.FindValueType(value) == TinyTokenType.Invalid)
            {
                if (value is IDictionary dictionary)
                {
                    var o = new TinyObject();
                    foreach (var key in dictionary.Keys)
                    {
                        o.Add((string)key, ToToken(dictionary[key]));
                    }
                    return(o);
                }

                if (value is IEnumerable enumerable)
                {
                    return(new TinyArray(enumerable));
                }
            }

            return(new TinyValue(value));
        }