protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); if (Comment?.Alignment == Alignment.Top) { block.AppendFormat(Comment.ToString()); Comment.Clear(); } if (Expression != null) { block.AppendFormat("{0}{1}", $"{Signature} => {Expression};", Comment); } else if (Gets.Count == 0 && Sets.Count == 0) { if (value != null) { block.AppendFormat("{0}{1}", $"{Signature} {{ {get}; {set}; }} = {value};", Comment); } else { block.AppendFormat("{0}{1}", $"{Signature} {{ {get}; {set}; }}", Comment); } } else if (!IsLambda) { block.AppendLine(Signature + Comment); block.Begin(); if (Gets.Count != 0) { block.AppendLine(get); block.AddWithBeginEnd(Gets); } if (Sets.Count != 0) { block.AppendLine(set); block.AddWithBeginEnd(Sets); } block.End(); } else { block.AppendLine(Signature + Comment); if (Gets.Count != 0) { Lambda(block, get, Gets); } if (Sets.Count != 0) { Lambda(block, set, Sets); } } return; }
protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); block.AppendLine(signature); block.AddWithBeginEnd(Body); }
protected override void BuildBlock(CodeBlock block) { foreach (var name in usings) { block.AppendFormat("using {0};", name); } block.AppendLine(); block.AppendFormat("namespace {0}", this.Namespace); var c = new CodeBlock(); classes.ForEach( clss => c.Add(clss.GetBlock()), clss => c.AppendLine() ); block.AddWithBeginEnd(c); }
protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); block.AppendLine(Signature); var body = new CodeBlock(); Features.ForEach( item => body.Add(item), item => { if (item.Count == 1) { return; } body.AppendLine(); } ); block.AddWithBeginEnd(body); }
public void Output(string directory) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } foreach (Prototype clss in classes) { CodeBlock block = new CodeBlock(); foreach (var name in usings) { block.AppendFormat("using {0};", name); } block.AppendLine(); block.AppendFormat("namespace {0}", this.Namespace); var c = new CodeBlock(); c.Add(clss.GetBlock()); block.AddWithBeginEnd(c); string code = block.ToString(); string folder = directory; if (!string.IsNullOrEmpty(clss.Subdirectory)) { folder = Path.Combine(directory, clss.Subdirectory); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } string file = Path.ChangeExtension(Path.Combine(folder, clss.Name), "cs"); File.WriteAllText(file, code); } }
protected override void BuildBlock(CodeBlock clss) { base.BuildBlock(clss); if (Comment != null) { Comment.Alignment = Alignment.Top; clss.AppendFormat($"{Comment}"); } clss.AppendFormat("{0} class {1}", new ModifierString(Modifier), base.Name); if (Inherits.Length > 0) { clss.AppendFormat("\t: {0}", string.Join(", ", Inherits.Select(inherit => inherit.ToString()))); } var body = new CodeBlock(); if (Sorted) { var flds = fields.Where(fld => (fld.Modifier & Modifier.Const) != Modifier.Const); foreach (Field field in flds.OrderBy(fld => fld.Modifier)) { body.Add(field); } foreach (Constructor constructor in constructors) { body.Add(constructor); body.AppendLine(); } foreach (Property property in properties) { body.Add(property); if (property.GetBlock().Count > 1) { body.AppendLine(); } } foreach (Method method in methods) { body.Add(method); body.AppendLine(); } flds = fields.Where(fld => (fld.Modifier & Modifier.Const) == Modifier.Const); if (flds.Count() > 0) { body.AppendLine(); foreach (Field field in flds) { body.Add(field); } } foreach (Class _class in classes) { body.Add(_class); body.AppendLine(); } } else { list.ForEach( item => body.Add(item), item => { if (item.Count == 1 && (item is Field || item is Property)) { return; } //if (item.Count == 1 && (item is Member)) // return; body.AppendLine(); } ); } clss.AddWithBeginEnd(body); }