public void OldVisit(MessageExpression expression)
{
string selector = expression.Selector;
bool nested = false;
if (expression.Target is MessageExpression && ((MessageExpression)expression.Target).IsBinaryMessage)
nested = true;
else if (expression.Target is SetExpression)
nested = true;
else if (expression.Target is BlockExpression)
nested = true;
if (!char.IsLetter(selector[0]) && expression.Arguments.Count() == 1)
{
if (nested)
this.writer.Write("(");
// TODO Refactor: repeated code below
if (expression.Target is ConstantExpression)
{
ConstantExpression cexpr = (ConstantExpression)expression.Target;
// TODO other types, scape characters in string
if (cexpr.Value is string)
this.writer.Write(string.Format("String({0})", cexpr.AsString()));
else if (cexpr.Value is int)
this.writer.Write(string.Format("Number({0})", cexpr.Value));
else if (cexpr.Value is bool)
this.writer.Write(string.Format("Boolean({0})", cexpr.Value));
}
else
expression.Target.Visit(this);
if (nested)
this.writer.Write(")");
if (OperatorHasMethodName(selector))
{
this.writer.Write("." + OperatorToMethodName(selector) + "(");
expression.Arguments.First().Visit(this);
this.writer.Write(")");
}
else
{
this.writer.Write(" " + OperatorToJsOperator(selector) + " ");
expression.Arguments.First().Visit(this);
}
return;
}
if (expression.Target is ConstantExpression)
{
ConstantExpression cexpr = (ConstantExpression)expression.Target;
// TODO other types, scape characters in string
if (cexpr.Value is string)
this.writer.Write(string.Format("String({0})", cexpr.AsString()));
else if (cexpr.Value is int)
this.writer.Write(string.Format("Number({0})", cexpr.Value));
else if (cexpr.Value is bool)
this.writer.Write(string.Format("Boolean({0})", cexpr.Value.ToString().ToLower()));
}
else
{
if (nested)
this.writer.Write("(");
expression.Target.Visit(this);
if (nested)
this.writer.Write(")");
}
this.writer.Write(string.Format(".{0}(", ToMethodName(expression.Selector)));
int narg = 0;
foreach (var argument in expression.Arguments)
{
if (narg != 0)
this.writer.Write(", ");
argument.Visit(this);
narg++;
}
this.writer.Write(")");
}