public string GenerateCode(CodeGenStyle style = null) { if (style == null) { style = new CodeGenStyle(); } var builder = new StringBuilder(style.Indent); builder.Append($"[{Name}"); if (Arguments.Count > 0) { var argList = string.Join(", ", Arguments); builder.Append($"({argList})"); } builder.Append("]"); return(builder.ToString()); }
public string GenerateCode(CodeGenStyle style = null) { if (style == null) { style = new CodeGenStyle(); } var builder = new StringBuilder(); if (Comment != null) { builder.AppendLine(Comment.GenerateCode(style)); } foreach (var attribute in Attributes) { builder.AppendLine(attribute.GenerateCode(style)); } builder.Append(style.Indent); builder.Append(Scope.ToString().ToLower()); builder.Append(" "); var argList = string.Join(", ", Parameters); builder.AppendLine($"{ClassName}({argList})"); builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; builder.AppendLine(style.IndentMultilineString(Body)); style.IndentCount--; builder.Append($"{style.Indent}}}"); return(builder.ToString()); }
public string GenerateCode(CodeGenStyle style = null) { if (style == null) { style = new CodeGenStyle(); } var builder = new StringBuilder(); foreach (var @using in Usings) { builder.AppendLine($"{style.Indent}using {@using};"); } if (Usings.Any()) { builder.AppendLine(); } builder.AppendLine($"{style.Indent}/// <auto-generated />"); builder.AppendLine($"{style.Indent}namespace {Name}"); builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; foreach (var content in Content) { builder.AppendLine(content.GenerateCode(style)); builder.AppendLine(); } style.IndentCount--; builder.AppendLine($"{style.Indent}}}"); return(builder.ToString()); }
public string GenerateCode(CodeGenStyle style = null) { if (style == null) { style = new CodeGenStyle(); } var builder = new StringBuilder(); if (Comment != null) { builder.AppendLine(Comment.GenerateCode(style)); } foreach (var attribute in Attributes) { builder.AppendLine(attribute.GenerateCode(style)); } builder.Append(style.Indent); builder.Append(Scope.ToString().ToLower()); builder.Append(" "); if (ClassType != ClassType.Normal) { builder.Append(ClassType.ToString().ToLower()); builder.Append(" "); } var genericList = GenericTypes.Any() ? $"<{string.Join(", ", GenericTypes.Select(gt => gt.Name))}>" : string.Empty; builder.Append($"class {Name}{genericList}"); if (DerivedFrom.Any()) { var derivedFromList = string.Join(", ", DerivedFrom); builder.Append($" : {derivedFromList}"); } builder.AppendLine(); foreach (var constrainedGeneric in GenericTypes.Where(gt => gt.Constraint != null)) { style.IndentCount++; builder.AppendLine($"{style.Indent}where {constrainedGeneric.Name} : {constrainedGeneric.Constraint}"); style.IndentCount--; } builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; foreach (var constructor in Constructors) { builder.AppendLine(constructor.GenerateCode(style)); builder.AppendLine(); } foreach (var variable in Variables) { builder.AppendLine(variable.GenerateCode(style)); builder.AppendLine(); } foreach (var property in Properties) { builder.AppendLine(property.GenerateCode(style)); builder.AppendLine(); } foreach (var method in Methods) { builder.AppendLine(method.GenerateCode(style)); builder.AppendLine(); } style.IndentCount--; builder.Append($"{style.Indent}}}"); return(builder.ToString()); }
public string GenerateCode(CodeGenStyle style = null) { if (style == null) { style = new CodeGenStyle(); } var builder = new StringBuilder(); if (Comment != null) { builder.AppendLine(Comment.GenerateCode(style)); } builder.Append(style.Indent); builder.Append(Scope.ToString().ToLower()); builder.Append(" "); builder.AppendLine($"{Type} {Name}"); builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; if (!string.IsNullOrWhiteSpace(GetMethodBody)) { builder.AppendLine($"{style.Indent}get"); builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; builder.AppendLine(style.IndentMultilineString(GetMethodBody)); style.IndentCount--; builder.AppendLine($"{style.Indent}}}"); } else { builder.AppendLine($"{style.Indent}get;"); } if (HasSet) { if (!string.IsNullOrWhiteSpace(SetMethodBody)) { builder.AppendLine($"{style.Indent}set"); builder.AppendLine($"{style.Indent}{{"); style.IndentCount++; builder.AppendLine(style.IndentMultilineString(SetMethodBody)); style.IndentCount--; builder.AppendLine($"{style.Indent}}}"); } else { builder.AppendLine($"{style.Indent}set;"); } } style.IndentCount--; builder.Append($"{style.Indent}}}"); if (!string.IsNullOrWhiteSpace(Initializer)) { builder.Append($" = {Initializer};"); } return(builder.ToString()); }