private void Render(JavaContext context, string templateName) { var template = templateLoader.Load(templateName); Enforce.IsNotNull(template, string.Format("No template for '{0}' found!", templateName)); template.Add("context", context); var tweakMap = new Dictionary<string, bool>(); var tweakValues = Enum.GetValues(typeof(GeneratorTweak)); foreach (var tweak in tweakValues) { tweakMap.Add(tweak.ToString(), config.ContainsTweak((GeneratorTweak)tweak)); } template.Add("tweaks", tweakMap); var packages = context.JavaPackage.Split('.'); DirectoryInfo folder = outputFolder; foreach (string pkg in packages) { folder = folder.CreateSubdirectory(pkg); } var file = new FileInfo(Path.Combine(folder.FullName, context.JavaName + ".java")); using (Stream stream = file.OpenWrite()) using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8)) { template.Write(new AutoIndentWriter(writer)); writer.Flush(); } }
private void Render(JavaContext context, string templateName) { var template = templateLoader.Load(templateName); Enforce.IsNotNull(template, string.Format("No template for '{0}' found!", templateName)); template.Add("context", context); var tweakMap = new Dictionary <string, bool>(); var tweakValues = Enum.GetValues(typeof(GeneratorTweak)); foreach (var tweak in tweakValues) { tweakMap.Add(tweak.ToString(), config.ContainsTweak((GeneratorTweak)tweak)); } template.Add("tweaks", tweakMap); var globalValues = new Dictionary <string, string>(); var codeGenVersion = Assembly.GetExecutingAssembly().GetName().Version; globalValues.Add("CodeGenVersion", codeGenVersion.ToString()); template.Add("global", globalValues); var packages = context.JavaPackage.Split('.'); DirectoryInfo folder = outputFolder; foreach (string pkg in packages) { folder = folder.CreateSubdirectory(pkg); } var filename = Path.Combine(folder.FullName, context.JavaName + ".java"); using (StreamWriter writer = new StreamWriter(filename, false /*, Encoding.UTF8*/)) { template.Write(new AutoIndentWriter(writer)); writer.Flush(); } }