private static async Task <string> ReplaceTokensAsync(Project project, TemplateInfo template, string relative, string templateFullName) { if (string.IsNullOrEmpty(templateFullName)) { return(templateFullName); } string rootNs = project.GetRootNamespace(); string ns = string.IsNullOrEmpty(rootNs) ? "MyNamespace" : rootNs; if (!string.IsNullOrEmpty(relative)) { ns += "." + ProjectHelpers.CleanNameSpace(relative); } using (var reader = new StreamReader(templateFullName)) { string content = await reader.ReadToEndAsync(); var itemname = template.ShortItemName; return(content.Replace("{namespace}", ns) .Replace("{itemname}", itemname)); } }
private static async Task <string> ReplaceTokensAsync(Project project, string name, string relative, string templateFile, TemplateType templateType, string inputCamel) { if (string.IsNullOrEmpty(templateFile)) { return(templateFile); } string rootNs = project.GetRootNamespace(); string ns = string.IsNullOrEmpty(rootNs) ? "MyNamespace" : rootNs; if (!string.IsNullOrEmpty(relative)) { ns += "." + ProjectHelpers.CleanNameSpace(relative); } if (templateType.ToString().EndsWith("Dto") && !ns.EndsWith("Dto")) { ns += ".Dto"; } using (var reader = new StreamReader(templateFile)) { string content = await reader.ReadToEndAsync(); content = content.Replace("{namespace}", ns) .Replace("{classname}", name); if (templateType == TemplateType.Class || templateType == TemplateType.Interface) { content = content.Replace("{entity}", inputCamel) .Replace("{pageddto}", $"Paged{inputCamel}ResultRequestDto") .Replace("{defaultdto}", $"{inputCamel}Dto") .Replace("{createdto}", $"Create{inputCamel}Dto") .Replace("{updatedto}", $"Update{inputCamel}Dto") .Replace("{interface}", $"I{inputCamel}AppService") ; } else if (templateType == TemplateType.MapProfile) { content = content.Replace("{entity}", inputCamel) .Replace("{defaultdto}", $"{inputCamel}Dto") .Replace("{createdto}", $"Create{inputCamel}Dto") .Replace("{updatedto}", $"Update{inputCamel}Dto") ; } return(content); } }