public virtual string Translate()
{
FormatWriter writer = new FormatWriter()
{
Formatter = this.Formatter
};
// TODO: Improve this logic to make it more readable and efficient
if (this.type != null)
{
if (this.Expression == null)
{
// [var ]<name> : <type>
writer.Write("{0}{1} {2} {3}",
text => ClassDeclarationCodePerfect.RefineDeclaration(text),
this.shouldRenderDeclarationKeyword ? Lexems.VariableDeclaratorKeyword + " " : string.Empty,
this.names[0].Translate(),
Lexems.Colon,
this.type.Translate());
}
else
{
// [var ]<name> : <type> = <expression>
writer.Write("{0}{1} {2} {3} {4} {5}",
text => ClassDeclarationCodePerfect.RefineDeclaration(text),
this.shouldRenderDeclarationKeyword ? Lexems.VariableDeclaratorKeyword + " " : string.Empty,
this.names[0].Translate(),
Lexems.Colon,
this.type.Translate(),
Lexems.EqualsSign,
this.Expression.Translate());
}
}
else
{
if (this.Expression == null)
{
// var <name>
writer.Write("{0} {1}",
text => ClassDeclarationCodePerfect.RefineDeclaration(text),
Lexems.VariableDeclaratorKeyword,
this.names[0].Translate());
}
else
{
// var <name> = <expression>
writer.Write("{0} {1} {2} {3}",
text => ClassDeclarationCodePerfect.RefineDeclaration(text),
Lexems.VariableDeclaratorKeyword,
this.names[0].Translate(),
Lexems.EqualsSign,
this.Expression.Translate());
}
}
return writer.ToString();
}