Elight.Utility/Extension/Template.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Elight.Utility.Extension
{
/// <summary>
/// 模版引擎
/// </summary>
public class Template
{
private string Content { get; set; }
/// <summary>
/// 模版引擎
/// </summary>
/// <param name="content"></param>
public Template(string content)
{
Content = content;
}
/// <summary>
/// 创建模板
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static Template Create(string content)
{
return new Template(content);
}
/// <summary>
/// 设置变量
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public Template Set(string key, string value)
{
Content = Content.Replace("{{" + key + "}}", value);
return this;
}
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="check">是否检查未使用的模板变量</param>
/// <returns></returns>
public string Render(bool check = false)
{
if (check)
{
var mc = Regex.Matches(Content, @"\{\{.+?\}\}");
foreach (Match m in mc)
{
throw new ArgumentException($"模版变量{m.Value}未被使用");
后面还有 7 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。