Permalink
Browse files

Merge remote branch 'craig/master'

  • Loading branch information...
lanwin committed Jul 22, 2010
2 parents 9a6ea33 + 3a64923 commit 53b848a608b7e381438daec8a96e0db62c71c96f
Showing with 19 additions and 7 deletions.
  1. +1 −7 source/MongoDB/Linq/Translators/JavascriptFormatter.cs
  2. +18 −0 source/MongoDB/Util/JsonFormatter.cs
@@ -240,7 +240,6 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
protected override NewExpression VisitNew(NewExpression nex)
{
_js.Append(new JavascriptObjectFormatter().FormatObject(nex));
-
return nex;
}
@@ -283,12 +282,7 @@ private static T EvaluateConstant<T>(Expression e)
private static string GetJavascriptValueForConstant(ConstantExpression c)
{
- if (c.Value == null)
- return "null";
- if (c.Type == typeof(string) || c.Type == typeof(StringBuilder))
- return string.Format(@"""{0}""", c.Value);
-
- return c.Value.ToString();
+ return JsonFormatter.SerializeForServerSide(c.Value);
}
private class JavascriptObjectFormatter : MongoExpressionVisitor
@@ -33,6 +33,24 @@ public static string Serialize(Document doc)
return json.ToString();
}
+ /// <summary>
+ /// Serializes for server side.
+ /// </summary>
+ /// <param name="value">The value.</param>
+ /// <returns></returns>
+ public static string SerializeForServerSide(object value)
+ {
+ var sb = new StringBuilder();
+ if (value is DateTime)
+ {
+ DateTime d = (DateTime)value;
+ sb.AppendFormat("new Date({0},{1},{2},{3},{4},{5},{6})", d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, d.Millisecond);
+ }
+ else
+ SerializeType(value, sb);
+ return sb.ToString();
+ }
+
/// <summary>
/// Serializes the type.
/// </summary>

0 comments on commit 53b848a

Please sign in to comment.