using System; using System.Text.RegularExpressions; namespace Masuit.Tools.Strings { /// /// 模版引擎 /// public class Template { private string Content { get; set; } /// /// 模版引擎 /// /// public Template(string content) { Content = content; } /// /// 设置变量 /// /// /// /// public Template Set(string key, string value) { Content = Content.Replace("{{" + key + "}}", value); return this; } /// /// 渲染模板 /// /// public string Render() { var mc = Regex.Matches(Content, @"\{\{.+?\}\}"); foreach (Match m in mc) { throw new ArgumentException($"模版变量{m.Value}未被使用"); } return Content; } } }