private bool Doing(object args) { using (CodeGeneratorScope.CreateScope()) { var argument = (RuntimeArgument)args; if (!BeginDo(argument)) { return(false); } try { foreach (var entity in argument.Entities) { Execute(entity); } foreach (var project in argument.Projects) { Execute(project); } return(true); } finally { EndDo(argument); } } }
public override void Run(TextWriter writer, CodeBlock source) { using (var scope = new CodeGeneratorScope(writer, args => args.WriteLine(" {"), args => args.Write("}"))) { if (!string.IsNullOrEmpty(source?.Content)) { scope.Writer.WriteLine(source.Content); } } }
public string SingleScope() { StringWriter writer = new StringWriter(); CodeGeneratorScope scope = new CodeGeneratorScope(writer, args => args.WriteLine("{"), args => args.WriteLine("}")); using (scope) { scope.Writer.WriteLine("int i = 100;"); } return(writer.ToString().RemoveCarriageReturn()); }
/// <summary> /// 执行器 /// </summary> public bool Execute(ProjectConfig project) { StateMessage = "正在生成" + project.Caption + "..."; using (CodeGeneratorScope.CreateScope()) { _builder.CreateProjectCode(project); } StateMessage = project.Caption + "已完成"; return(true); }
/// <summary> /// 执行器 /// </summary> public bool Execute(EntityConfig entity) { StateMessage = "正在生成" + entity.Caption + "..."; using (CodeGeneratorScope.CreateScope()) { _builder.CreateEntityCode(entity.Parent, entity); } StateMessage = entity.Caption + "已完成"; return(true); }
public static string DoCoder <T>(Func <T, string> func, T t) //where T : ConfigBase, new() { using (CodeGeneratorScope.CreateScope()) { return(func(t)); //var arg = new T(); //arg.Copy(t); //return func(arg); } }
public void SingleScope() { StringWriter writer = new StringWriter(); CodeGeneratorScope scope = new CodeGeneratorScope(writer, args => args.WriteLine("{"), args => args.WriteLine("}")); using (scope) { scope.Writer.WriteLine("int i = 100;"); } string result = writer.ToString().RemoveCarriageReturn(); Assert.Equal(SingleScopeResult, result); }
public string NestedScope() { StringWriter writer = new StringWriter(); using (CodeGeneratorScope scope = new CodeGeneratorScope(writer, args => args.WriteLine("{"), args => args.WriteLine("}"))){ scope.Writer.WriteLine("int i = 100;"); using (var child = scope.Writer.BeginScope("test")) { child.Writer.WriteLine("int a = 200;"); } } return(writer.ToString().RemoveCarriageReturn()); }
/// <summary> /// 取得其它生成器的能力 /// </summary> /// <typeparam name="TBuilder"></typeparam> /// <returns></returns> public string GetExtendCode <TBuilder>() where TBuilder : EntityBuilderBase, new() { using (CodeGeneratorScope.CreateScope()) { var builder = new TBuilder { Entity = Entity, Project = Project }; return(builder.ExtendCode); } }
public void NestedScope() { StringWriter writer = new StringWriter(); using (CodeGeneratorScope scope = new CodeGeneratorScope(writer, args => args.WriteLine("{"), args => args.WriteLine("}"))) { scope.Writer.WriteLine("int i = 100;"); using (var child = scope.Writer.BeginScope("test")) { child.Writer.WriteLine("int a = 200;"); } } string result = writer.ToString().RemoveCarriageReturn(); Assert.Equal(NestedScopeResult, result); }
/// <summary> /// 执行目标的动作 /// </summary> /// <param name="config"></param> /// <param name="coder"></param> /// <returns></returns> public string CreateCode <TConfig>(ConfigBase config, Func <TConfig, string> coder) where TConfig : ConfigBase { StringBuilder code = new StringBuilder(); using (CodeGeneratorScope.CreateScope()) { config.Foreach <TConfig>(arg => { code.AppendLine(coder(arg)); }); } return(code.ToString()); }
/// <summary> /// 生成基础代码 /// </summary> public void CreateBaseCode(string path) { using (CodeGeneratorScope.CreateScope()) { try { CurrentIsExtend = false; CurrentPath = path; if (CanWrite) { CreateBaCode(path); } } catch (Exception e) { Trace.Write(e, this.GetTypeName()); } } }