调整了Library文件结构;

源代码生成新增了参数验证方法;
修改了ParamterDetails的定义
This commit is contained in:
fengjiayi
2025-07-29 18:36:43 +08:00
parent b6ed0b69dc
commit 8dc7f5dd9b
20 changed files with 272 additions and 241 deletions

View File

@@ -69,6 +69,14 @@ namespace Serein.Library
/// 是否禁止参数进行修改(初始化后不能再通过 Setter 修改)
/// </summary>
public bool IsProtection = false;
/// <summary>
/// 是否需要验证参数
/// </summary>
public bool IsVerify = false;
/*
/// <summary>
/// 自定义代码(属性变更前)

View File

@@ -146,9 +146,17 @@ namespace Serein.Library.NodeGenerator
var attributeInfo = fieldKV.Value; // 缓存的特性信息
var isProtection = attributeInfo.Search(nameof(PropertyInfo), nameof(PropertyInfo.IsProtection), value => bool.Parse(value)); // 是否为保护字段
var isVerify = attributeInfo.Search(nameof(PropertyInfo), nameof(PropertyInfo.IsVerify), value => bool.Parse(value)); // 是否为保护字段
//sb.AppendLine(leadingTrivia);
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} oldValue, {fieldType} newValue);");
sb.AppendLine($" partial void On{propertyName}Changed({fieldType} value);");
if (isVerify)
{
sb.AppendLine($" partial void BeforeThe{propertyName}(ref bool __isAllow, {fieldType} newValue);");
}
if (isProtection)
{
sb.AppendLine($" private bool __{propertyName}ProtectionField = false;");
@@ -164,7 +172,12 @@ namespace Serein.Library.NodeGenerator
sb.AppendLine( " set");
sb.AppendLine( " {");
//sb.AppendLine($" if ({fieldName} {(isProtection ? "== default" : "!= value")})"); // 非保护的Setter
if (isVerify)
{
sb.AppendLine($" bool __isAllow = true;");
sb.AppendLine($" BeforeThe{propertyName}(ref __isAllow, value);");
sb.AppendLine($" if(!__isAllow) return; // 修改验证失败");
}
sb.AppendLine($" var __oldValue = {fieldName};");
if (isProtection)
{