public override void CodeGen(CodeBuilder builder) { builder.AppendToken("if ("); builder.ForceNoWhitespace(); ConditionalExpression.CodeGen(builder); builder.AppendToken(")"); builder.BeginBlock(); ThenStatement.CodeGen(builder); builder.EndBlock(); if (ElseStatement != null) { builder.EndOfLine(); // Nur einfachen Zeilenumbruch erzwingen builder.AppendToken("else"); builder.BeginBlock(); ElseStatement.CodeGen(builder); builder.EndBlock(); } }
public override void CodeGen(CodeBuilder builder) { base.CodeGen(builder); Visibility.CodeGen(builder); Type.CodeGen(builder); builder.AppendToken(Name); builder.BeginBlock(); // Getter builder.AppendToken("get"); builder.BeginBlock(); GetterStatement.CodeGen(builder); builder.EndBlock(); builder.EndOfLine(); // EndBlock-Verhalten überschreiben, sodass keine Leerzeile entsteht // Setter builder.AppendToken("set"); builder.BeginBlock(); SetterStatement.CodeGen(builder); builder.EndBlock(); builder.EndBlock(); }
private void CodeGenConstructor(CodeBuilder builder, IReadOnlyList <PropertyBuilder> constructorProperties) { builder.AppendToken("public"); builder.AppendToken(Name); builder.ForceNoWhitespace(); builder.AppendToken("("); builder.ForceNoWhitespace(); builder.BeginSeparatedList(","); foreach (var property in constructorProperties) { property.Type.CodeGen(builder); builder.AppendToken(property.GenerateParameterName()); builder.EndOfSeparatedListItem(); } builder.EndOfSeparatedList(); builder.AppendToken(")"); builder.BeginBlock(); foreach (var property in constructorProperties) { builder.AppendToken(property.Name); builder.AppendToken("="); builder.AppendToken(property.GenerateParameterName()); builder.EndOfStatement(); } builder.EndBlock(); }
public void CodeGen(CodeBuilder builder) { if (string.IsNullOrEmpty(Namespace)) { throw new InvalidOperationException("Kein Namespace angegeben"); } // Header if (!string.IsNullOrEmpty(Header)) { builder.AppendMultiLineComment(Header); } // Using-Direktiven foreach (string u in Usings) { builder.AppendToken("using"); builder.AppendToken(u); builder.EndOfStatement(); } builder.EndOfLineBlock(); // Namespace builder.AppendToken("namespace"); builder.AppendToken(Namespace); builder.BeginBlock(); // Inhalt foreach (var module in Modules) { module.CodeGen(builder); } builder.EndBlock(); }
public void CodeGen(CodeBuilder builder) { Visibility.CodeGen(builder); switch (ModuleType) { case ModuleTypes.Class: builder.AppendToken("class"); break; case ModuleTypes.Struct: builder.AppendToken("struct"); break; default: throw new ArgumentOutOfRangeException(); } builder.AppendToken(Name); if (Inheritations.Any()) { builder.AppendToken(":"); builder.BeginSeparatedList(","); foreach (var inheritation in Inheritations) { inheritation.CodeGen(builder); builder.EndOfSeparatedListItem(); } builder.EndOfSeparatedList(); } builder.BeginBlock(); foreach (var constant in Constants) { constant.CodeGen(builder); } // Leerzeile nach den Konstanten if (Constants.Any()) { builder.EndOfLineBlock(); } // Konstruktor erzeugen var constructorProperties = Properties.Where(p => p.SetInConstructor).ToList(); if (constructorProperties.Any()) { CodeGenConstructor(builder, constructorProperties); } foreach (var property in Properties) { property.CodeGen(builder); } foreach (var method in Methods) { method.CodeGen(builder); } foreach (string code in StaticCode) { builder.AppendStaticCode(code); } builder.EndBlock(); }