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 block) { base.BuildBlock(block); switch (value) { case Value x: x.BuildBlock(block); break; case New instance: block.Add(instance); break; case Array A: if (Type == TypeInfo.Anonymous) { Type = new TypeInfo { Type = A.GetType() } } ; block.Append($"new {Type}"); WriteArrayValue(block, A, 10); break; case Dictionary <object, object> dict: block.Append($"new {Type}"); WriteDictionary(block, dict); break; default: block.Append(Primitive.ToPrimitive(value)); break; } }
protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); block.Add(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); }
private string FillAndCollect() { Method fill = new Method("FillObject") { modifier = Modifier.Public | Modifier.Override, args = new Arguments().Add<DataRow>("row") }; Method collect = new Method("UpdateRow") { modifier = Modifier.Public | Modifier.Override, args = new Arguments().Add<DataRow>("row") }; foreach (IColumn column in metaTable.Columns) { var fieldDef = dict_column_field[column.ColumnName]; string fieldName = fieldDef.PropertyName; fill.statements.AppendFormat("this.{0} = GetField<{1}>(row, _{0});", fieldName, fieldDef.Type); collect.statements.AppendFormat("SetField(row, _{0}, this.{0});", fieldName); } clss.Add(fill); clss.Add(collect); CodeBlock block = new CodeBlock(); block.Add(fill); block.AppendLine(); block.Add(collect); return block.ToString(2); }