/// <summary>
        /// Converts any object into an <see cref="Expression" /> object.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Expression FromObject(object value)
        {
            Expression result = value as Expression;

            if (result != null)
            {
                return(result);
            }

            IEnumerable enumerable;
            IDictionary dictionary;
            string      str;
            double      d;

            if (value == null)
            {
                result = JS.Null();
            }
            else if ((str = value as string) != null)
            {
                result = FromString(str);
            }
            else if (value is Statement)
            {
                throw new InvalidOperationException("A statement cannot be used as an expression.");
            }
            else if ((dictionary = value as IDictionary) != null)
            {
                result = ObjectLiteralExpression.FromDictionary(dictionary);
            }
            else if ((enumerable = value as IEnumerable) != null)
            {
                result = JS.ArrayOrObject(enumerable);
            }
            else if (value.GetType().IsClass)
            {
                result = JS.Object(JS.GetValues(value));
            }
            else if (value is Boolean)
            {
                result = FromBoolean((bool)value);
            }
            else if (double.TryParse(Convert.ToString(value, CultureInfo.InvariantCulture), NumberStyles.Any, CultureInfo.InvariantCulture, out d))
            {
                result = FromDouble(d);
            }
            else
            {
                result = FromString(value.ToString());
            }

            return(result);
        }
        /// <summary>
        /// Uses reflection to find out if the specified sequence implements any <see cref="IEnumerable{KeyValuePair}" />
        /// and returns an <see cref="ObjectLiteralExpression" /> in that case, or an <see cref="ArrayExpression" /> if not.
        /// </summary>
        /// <param name="enumerable">The sequence to convert.</param>
        /// <returns>Either an instance of <see cref="ObjectLiteralExpression" /> or <see cref="ArrayExpression" />.</returns>
        public static Expression ArrayOrObject(IEnumerable enumerable)
        {
            Type keyValuePairEnumerableType = GetObjectsFirstIEnumerableKeyValuePairInterface(enumerable);

            if (keyValuePairEnumerableType == null)
            {
                return(Array(enumerable));
            }

            var keyProperty   = keyValuePairEnumerableType.GetProperty("Key");
            var valueProperty = keyValuePairEnumerableType.GetProperty("Value");

            return(ObjectLiteralExpression.FromDictionary <object, object>(enumerable.Cast <object>().ToDictionary(
                                                                               pair => keyProperty.GetValue(pair, null),
                                                                               pair => valueProperty.GetValue(pair, null))));
        }