protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); string _comment = string.Empty; if (Comment != null) { _comment = Comment.ToString(); if (Comment.Alignment == Alignment.Top) { block.Append(_comment); _comment = string.Empty; } } if (UserValue != null) { block.AppendLine($"{Signature} = {UserValue};{_comment}"); } else if (value != null) { block.AppendLine(); block.Append($"{Signature} = "); block.Append(value); block.Append(";"); } else { block.AppendLine($"{Signature};{_comment}"); } }
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); }
private void WriteDictionary(CodeBlock block, Dictionary <string, Value> A) { switch (format) { case ValueOutputFormat.SingleLine: block.Append("{"); A.ForEach( kvp => { block.Append($"{kvp.Key} = "); kvp.Value.BuildCode(block); }, _ => block.Append(",") ); block.Append("}"); break; default: block.Begin(); A.ForEach( kvp => { block.AppendLine(); block.Append($"{kvp.Key} = "); kvp.Value.BuildCode(block); }, _ => block.Append(",") ); block.End(); break; } }
private void OutputExpressions(CodeBlock block) { switch (Format) { case ValueOutputFormat.SingleLine: block.Append(" { "); expressions.ForEach( expr => { block.Append(expr); }, _ => block.Append(", ") ); block.Append(" }"); break; default: block.Begin(); expressions.ForEach( expr => { block.AppendLine(); block.Append(expr); }, _ => block.Append(",") ); block.End(); break; } }
private void WriteDictionary(CodeBlock block, Dictionary <object, object> dict) { switch (Format) { case ValueOutputFormat.SingleLine: block.Append("{"); dict.ForEach( kvp => { block.Append($"[{kvp.Key}] = "); NewValue(kvp.Value).BuildBlock(block); }, _ => block.Append(",") ); block.Append("}"); break; default: block.Begin(); dict.ForEach( kvp => { block.AppendLine(); block.Append($"[{kvp.Key}] = "); NewValue(kvp.Value).BuildBlock(block); }, _ => block.Append(",") ); block.End(); break; } }
protected override void BuildBlock(CodeBlock block) { if (attributes.Count != 0) { foreach (var attr in attributes) { block.AppendLine(attr.ToString()); } } }
protected override void BuildBlock(CodeBlock block) { base.BuildBlock(block); if (Comment?.Alignment == Alignment.Top) { block.AppendFormat(Comment.ToString()); Comment.Clear(); } if (Value != null) { block.AppendLine($"{Name} = {Value}, {Comment}"); } else { block.AppendLine($"{Name}, {Comment}"); } }
protected override void BuildBlock(CodeBlock block) { if (IsExpressionBodied) { block.Append(signature); //print in next line if (NextLine) { block.AppendLine(); } block.Append($"=> {Body}"); return; } base.BuildBlock(block); }
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); } }
public Directive(string line) { code.AppendLine(line); }
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 void WriteArrayValue(CodeBlock block, Array A, int columnNumber) { Type ty = Type.GetElementType(); if (ty != null && ty.IsPrimitive) { if (A.Length < 30) { format = ValueOutputFormat.SingleLine; } else if (A.Length < 100) { format = ValueOutputFormat.Wrap; columnNumber = 10; } else { format = ValueOutputFormat.Wrap; columnNumber = 20; } } switch (format) { case ValueOutputFormat.SingleLine: block.Append("{"); A.OfType <object>().ForEach( x => { NewValue(x).BuildCode(block); }, _ => block.Append(",") ); block.Append("}"); break; case ValueOutputFormat.Wrap: block.Begin(); for (int i = 0; i < A.Length; i++) { if (i % columnNumber == 0) { block.AppendLine(); } if (i != 0 && i % (columnNumber * 10) == 0) //add empty line every 10 lines { block.AppendLine(); } Value item = NewValue(A.GetValue(i)); item.BuildCode(block); if (i != A.Length - 1) { block.Append(","); } } block.End(); break; default: block.Begin(); for (int i = 0; i < A.Length; i++) { if (i != 0 && i % columnNumber == 0) { block.AppendLine(); } block.AppendLine(); Value item = NewValue(A.GetValue(i)); item.BuildCode(block); if (i != A.Length - 1) { block.Append(","); } } block.End(); break; } }
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); }