Exemplo n.º 1
0
        public override string Build()
        {
            if (string.IsNullOrEmpty(name))
            {
                if (value == null)
                {
                    return("null");
                }

                var str = value as string;
                if (str != null)
                {
                    return(string.Format("\"{0}\"", JQueryUtility.EncodeJsString(str)));
                }

                if (value is DateTime)
                {
                    var dt = (DateTime)value;
                    return(string.Format("new Date({0})", JQueryUtility.GetUnixMilliseconds(dt)));
                }

                return(string.Format("{0}", value));
            }
            else
            {
                if (value == null)
                {
                    return(string.Format("var {0} = null;", name));
                }

                var str = value as string;
                if (str != null)
                {
                    return(string.Format("var {0} = \"{1}\";", name, JQueryUtility.EncodeJsString(str)));
                }

                if (value is DateTime)
                {
                    var dt = (DateTime)value;
                    return(string.Format("var {0} = new Date({1});", name, JQueryUtility.GetUnixMilliseconds(dt)));
                }

                return(string.Format("var {0} = {1};", name, value));
            }
        }
Exemplo n.º 2
0
        public override string Build()
        {
            if (insideObject)
            {
                if (right == null)
                {
                    return(string.Format("\"{0}\": null", left));
                }

                var str = right as string;
                if (str != null)
                {
                    return(string.Format("\"{0}\": \"{1}\"", left, JQueryUtility.EncodeJsString(str)));
                }

                if (right is DateTime)
                {
                    var dt = (DateTime)right;
                    return(string.Format("\"{0}\": new Date({1})", left, JQueryUtility.GetUnixMilliseconds(dt)));
                }

                return(string.Format("\"{0}\": {1}", left, right));
            }
            else
            {
                if (right == null)
                {
                    return(string.Format("{0} = null;", left));
                }

                var str = right as string;
                if (str != null)
                {
                    return(string.Format("{0} = \"{1}\";", left, JQueryUtility.EncodeJsString(str)));
                }

                if (right is DateTime)
                {
                    var dt = (DateTime)right;
                    return(string.Format("{0} = new Date({1});", left, JQueryUtility.GetUnixMilliseconds(dt)));
                }

                return(string.Format("{0} = {1};", left, right));
            }
        }