private void BuildCodeByViewSchema(object item) { SOView view = item as SOView; List <SOColumn> columnList = DbSchemaHelper.Instance.CurrentSchema.GetViewColumnList(view); //生成代码文件 ViewHost host = new ViewHost(); host.View = view; host.ColumnList = columnList; host.TemplateFile = templateFile; foreach (object obj in listBox3.Items) { string[] ss = obj.ToString().Split('|'); host.SetValue(ss[0], ss[1].Replace("[<->]", "|")); } Engine engine = new Engine(); string fileName = string.Empty; string separator = txtFileNamePrefix.Text.Trim(); if (separator != "") { fileName = string.Format("{0}{1}", view.Name.RemovePrefix(separator, 10), host.FileExtention); } else { fileName = string.Format("{0}{1}", view.Name, host.FileExtention); } string outputContent = engine.ProcessTemplate(File.ReadAllText(templateFile), host); string outputFile = Path.Combine(outputPath, fileName); StringBuilder sb = new StringBuilder(); if (host.ErrorCollection.HasErrors) { foreach (CompilerError err in host.ErrorCollection) { sb.AppendLine(err.ToString()); } outputContent = outputContent + Environment.NewLine + sb.ToString(); outputFile = outputFile + ".error"; } if (Directory.Exists(outputPath) == false) { Directory.CreateDirectory(outputPath); } File.WriteAllText(outputFile, outputContent, Encoding.UTF8); }