Skip to content

Commit

Permalink
Merge remote branch 'craig/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Jul 22, 2010
2 parents 9a6ea33 + 3a64923 commit 53b848a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 1 addition & 7 deletions source/MongoDB/Linq/Translators/JavascriptFormatter.cs
Expand Up @@ -240,7 +240,6 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
protected override NewExpression VisitNew(NewExpression nex)
{
_js.Append(new JavascriptObjectFormatter().FormatObject(nex));

return nex;
}

Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions source/MongoDB/Util/JsonFormatter.cs
Expand Up @@ -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>
Expand Down

0 comments on commit 53b848a

Please sign in to comment.