public override string ToString(Formatting formatting) { if (Properties.IsEmpty()) { return("{}"); } var sb = new StringBuilder(); sb.Append("{"); formatting.IncreaseIndentation(); { sb.Append(formatting.NewLine); sb.Append(formatting.Indentation); sb.Append(string.Join("," + formatting.NewLine + formatting.Indentation, Properties.Select(p => string.Format("'{0}': {1}", p.Key, p.Value.ToString(formatting))))); sb.Append(formatting.NewLine); } formatting.DecreaseIndentation(); sb.Append(formatting.Indentation + "}"); return(sb.ToString()); }
public override string ToString(Formatting formatting) { if (Values == null || Values.IsEmpty()) { return("[]"); } var sb = new StringBuilder(); sb.Append("["); formatting.IncreaseIndentation(); { if (!Inline) { sb.Append(formatting.NewLine); sb.Append(formatting.Indentation); } var separatingWhitespace = Inline ? " " : formatting.NewLine + formatting.Indentation; sb.Append(string.Join("," + separatingWhitespace, GetChildren().Select(p => p.ToString(formatting)))); if (!Inline) { sb.Append(formatting.NewLine); } } formatting.DecreaseIndentation(); if (Inline) { sb.Append("]"); } else { sb.Append(formatting.Indentation + "]"); } return(sb.ToString()); }
public override string ToString(Formatting formatting) { var s = ""; var function = Function; if (IsIdentifier(function)) { s += Function.ToString(formatting); } else { s += "(" + Function.ToString(formatting) + ")"; } formatting.IncreaseIndentation(); string prefix; if (Indent) { prefix = formatting.NewLine + formatting.Indentation; } else { prefix = ""; } if (Arguments != null) { s += string.Format("({0}{1})", prefix, string.Join("," + prefix, Arguments.Select(a => a.ToString(formatting)))); } else { s += "()"; } formatting.DecreaseIndentation(); return(s); }
public override string ToString(Formatting formatting) { var sb = new StringBuilder(); sb.Append(formatting.NewLine + formatting.Indentation + "switch ("); sb.Append(Value.ToString(formatting)); sb.Append("){"); formatting.IncreaseIndentation(); if (Statements != null) { sb.Append(formatting.NewLine); sb.Append(formatting.Indentation); sb.Append(string.Join(formatting.NewLine + formatting.Indentation, Statements.Select(s => s.ToString(formatting)))); } formatting.DecreaseIndentation(); sb.Append(formatting.NewLine + formatting.Indentation + "}"); return(sb.ToString()); }
public override string ToString(Formatting formatting) { var sb = new StringBuilder(); sb.Append(formatting.NewLine + formatting.Indentation + "try {"); formatting.IncreaseIndentation(); if (Statements != null) { foreach (var s in Statements) { sb.Append(formatting.NewLine + formatting.Indentation); sb.Append(s.ToString(formatting)); } } formatting.DecreaseIndentation(); sb.Append(formatting.NewLine + formatting.Indentation + "}"); return(sb.ToString()); }
public override string ToString(Formatting formatting) { var sb = new StringBuilder(); sb.Append("function "); if (Name != null) { sb.Append(Name); } sb.Append("("); if (Parameters != null) { sb.Append(string.Join(",", Parameters.Select(p => p.ToString(formatting)))); } sb.Append(")"); if (Inline) { sb.Append("{"); } else { sb.Append(formatting.NewLine + formatting.Indentation + "{"); } formatting.IncreaseIndentation(); { var variables = GetChildrenRecursive(a => a == this || !(a is JSFunctionDelcaration)) .OfType <JSVariableDelcaration>() .Select(v => v.Name) .Distinct(); var indent = Inline ? " " : formatting.NewLine + formatting.Indentation; if (variables.Any()) { sb.Append(indent); sb.Append(string.Join(indent, variables.Select(v => "var " + v + ";"))); } if (Body != null) { sb.Append(indent); sb.Append(string.Join(indent, Body.Select(p => p.ToString(formatting)).Where(s => !string.IsNullOrWhiteSpace(s)))); } } formatting.DecreaseIndentation(); if (Inline) { sb.Append("}"); } else { sb.Append(formatting.NewLine + formatting.Indentation + "}"); } return(sb.ToString()); }