1 Star 0 Fork 122

库卡青年/DevelopAssistant

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Creater.cs 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
wxd_tony1984 提交于 2017-06-10 11:09 +08:00 . 一些修改
using DevelopAssistant.Service.TemplatingEngine;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DevelopAssistant.Service
{
internal class Creater
{
internal static string CreateCode(TextTemplatingEngine host, string csType, string templateFile, string savePath,
string outType, out string message)
{
message = string.Empty;
host.TemplateFile = templateFile;
Microsoft.VisualStudio.TextTemplating.Engine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
string input = "";
string output = "";
try
{
if (!System.IO.File.Exists(host.TemplateFile))
{
throw new Exception("未找到 " + host.TemplateFile + " 模板文件");
}
input = System.IO.File.ReadAllText(host.TemplateFile);
output = engine.ProcessTemplate(input, host);
if (outType == "File")
{
try
{
string outputFile = savePath + host.ClassName + host.FileExtension;
if (System.IO.Directory.Exists(savePath))
{
System.IO.File.WriteAllText(outputFile, output);
}
else
{
System.IO.Directory.CreateDirectory(savePath);
System.IO.File.WriteAllText(outputFile, output);
}
}
catch (Exception error)
{
DevelopAssistant.Common.NLogger.WriteToLine(error.Message, "错误", DateTime.Now, error.Source, error.StackTrace);
message += error.ToString() + "\r\n";
}
}
message += host.ClassName + " " + csType + " 代码生成成功" + "\r\n";
foreach (CompilerError error in host.Errors)
{
message += error.ToString() + "\r\n";
}
}
catch (Exception ex)
{
DevelopAssistant.Common.NLogger.WriteToLine(ex.Message, "错误", DateTime.Now, ex.Source, ex.StackTrace);
}
return output;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wwwpythonpw/DevelopAssistant.git
git@gitee.com:wwwpythonpw/DevelopAssistant.git
wwwpythonpw
DevelopAssistant
DevelopAssistant
master

搜索帮助