Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed formatting of javascript in the linq implementation., CSHARP-52

  • Loading branch information...
commit 84bc53d583d2492d141babe55814da21d9abbd0b 1 parent ab62f7e
@craiggwilson craiggwilson authored
View
8 source/MongoDB/Linq/Translators/JavascriptFormatter.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
View
18 source/MongoDB/Util/JsonFormatter.cs
@@ -34,6 +34,24 @@ public static string Serialize(Document doc)
}
/// <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.Date, d.Hour, d.Minute, d.Second, d.Millisecond);
+ }
+ else
+ SerializeType(value, sb);
+ return sb.ToString();
+ }
+
+ /// <summary>
/// Serializes the type.
/// </summary>
/// <param name = "value">The value.</param>
Please sign in to comment.
Something went wrong with that request. Please try again.