static void Main(string[] args) { // InitRazorEngine(); //获得当前运行的Assembly Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.Template.ServiceFileTemplate.cshtml"); s.Position = 0; //将stream的其实点归零 StreamReader reader = new StreamReader(s, System.Text.Encoding.UTF8); string template = reader.ReadToEnd(); var model = new UserInfo { FirstName = "Bill", LastName = "Gates" }; var m2 = new ServiceFileModel { ServiceName = "Contract", Namespace = "Namespace", AppName = "AppName", InterfaceName = "InterfaceName" }; var result = Engine.Razor.RunCompile(template, "templateKey2", null, m2); Test(); string content = Engine.Razor.RunCompile("UserInfo", typeof(UserInfo), model); string a = Engine.Razor.RunCompile("ServiceFileTemplate", typeof(ServiceFileModel), m2); Console.WriteLine(content); Console.WriteLine(a); Console.Read(); }
private void CreateServiceFile(AddNewBusinessModel parameter, ProjectItem folder) { var fileName = parameter.ServiceName + ".cs"; _statusBar.Progress(true, $"Generating service file: {fileName}", _steps++, _totalSteps); if (FindProjectItem(folder, fileName, ItemType.PhysicalFile) != null) { return; } var model = new ServiceFileModel { BusinessName = parameter.BusinessName, AppName = _appName, Namespace = GetNamespace(parameter), InterfaceName = parameter.ServiceInterfaceName, ServiceName = parameter.ServiceName }; var template = GetTemplateText("ServiceFileTemplate"); var content = Engine.Razor.RunCompile(template, "ServiceFileModel", null, model); // string content = Engine.Razor.RunCompile("ServiceFileTemplate", typeof(ServiceFileModel), model); CreateAndAddFile(folder, fileName, content); }
/// <summary> /// 创建Service类 /// </summary> /// <param name="applicationStr">根命名空间</param> /// <param name="name">类名</param> /// <param name="dtoFolder">父文件夹</param> /// <param name="dirName">类所在文件夹目录</param> public static void CreateServiceFile(string applicationStr, string name, string cnName, Project dtoFolder, string dirName) { var model = new ServiceFileModel() { Namespace = applicationStr, Name = name, CnName = cnName, DirName = dirName.Replace("\\", ".") }; string content_IService = Engine.Razor.RunCompile("IServiceTemplate", typeof(ServiceFileModel), model); string fileName_IService = $"I{name}AppService.cs"; CommonHelper.AddFileToProjectItem(dtoFolder, content_IService, fileName_IService, name); //string content_Service = Engine.Razor.RunCompile("ServiceTemplate", typeof(ServiceFileModel), model); //string fileName_Service = $"{name}AppService.cs"; //CommonHelper.AddFileToProjectItem(dtoFolder, content_Service, fileName_Service); }
/// <summary> /// 创建Service类 /// </summary> /// <param name="applicationStr">根命名空间</param> /// <param name="name">类名</param> /// <param name="dtoFolder">父文件夹</param> /// <param name="dirName">类所在文件夹目录</param> private void CreateServiceFile(string applicationStr, string name, string cnName, ProjectItem dtoFolder, string dirName, CodeClass codeClass) { ThreadHelper.ThrowIfNotOnUIThread(); var model = new ServiceFileModel() { Namespace = applicationStr, Name = name, CnName = cnName, DirName = dirName.Replace("\\", ".") }; string content_IService = Engine.Razor.RunCompile("IServiceTemplate", typeof(ServiceFileModel), model); string fileName_IService = $"I{name}AppService.cs"; AddFileToProjectItem(dtoFolder, content_IService, fileName_IService); string content_Service = Engine.Razor.RunCompile("ServiceTemplate", typeof(ServiceFileModel), model); string fileName_Service = $"{name}AppService.cs"; AddFileToProjectItem(dtoFolder, content_Service, fileName_Service); }
/// <summary> /// 创建Service类 /// </summary> /// <param name="applicationStr">根命名空间</param> /// <param name="name">类名</param> /// <param name="dtoFolder">父文件夹</param> /// <param name="dirName">类所在文件夹目录</param> private static void CreateServiceFile(string applicationStr, string name, string cnName, Project dtoFolder, string dirName, CodeClass codeClass) { var model = new ServiceFileModel() { Namespace = applicationStr, Name = name, CnName = cnName, DirName = dirName.Replace("\\", ".") }; string path = @"D:\个人程序文件\个人项目\TuDou.CodeGenerate\CodeGenerate.vsix\Templates\IServiceTemplate.cshtml"; var template = File.ReadAllText(path); string content_IService = Engine.Razor.RunCompile(template, "IServiceTemplate", null, model); string fileName_IService = $"I{name}AppService.cs"; CommonHelper.AddFileToProjectItem(dtoFolder, content_IService, fileName_IService, name); string content_Service = Engine.Razor.RunCompile("ServiceTemplate", typeof(ServiceFileModel), model); string fileName_Service = $"{name}AppService.cs"; CommonHelper.AddFileToProjectItem(dtoFolder, content_Service, fileName_Service, name); }