internal virtual VerifyResult VerifyViaContext(VerifiableOpsContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (context.OpsMode == VerifiableOpsMode.Object) { return(VerifyImpl(context.VerifiableObjectContext)); } if (context.OpsMode == VerifiableOpsMode.Member) { return(VerifyOneImpl(context.VerifiableMemberContext)); } return(VerifyResult.Success); }
/// <summary> /// Verification. /// </summary> /// <param name="context"></param> public bool Verify(VerifiableOpsContext context) { var val = context.OpsMode switch { VerifiableOpsMode.Object => Valid(context.VerifiableObjectContext), VerifiableOpsMode.Member => Valid(context.VerifiableMemberContext), _ => null }; if (val is not null) { // 无论成功或失败, 都将 CorrectVerifyVal 写入 context 内 context.AppendVerifyVal(VerifiableMember.MemberName, val); // 过滤 CorrectVerifyVal 结果为 Success 的规则名 (!val.IsIgnore && !val.IsSuccess).IfFalse(v => context.AppendNameOfExecutedRule(v.NameOfExecutedRule), val); } return(val?.IsSuccess ?? true); }
public override void Verify(VerifiableOpsContext context) { for (var i = 0; i < Tokens.Count; i++) { var token = Tokens[i]; // 验证 // 如果验证结果为 true, InternalLogic 为 false (OR), 则 break 并返回 // 如果验证结果为 false, InternalLogic 为 true (AND), 应继续执行, 以获得完整的错误信息 if (token.Verify(context) && !InternalLogic) { break; } // 如果遇到 OR, 提升作用域 // 如果当前 token 是最后一个, 则不提升 Scope, 避免空 CorrectVerifyValBlock 干扰最终结果 if (!InternalLogic && i < Tokens.Count - 1) { context.RaiseScope(MemberName, InternalLogic ? ConditionOps.And : ConditionOps.Or); } } }
public virtual void Verify(VerifiableOpsContext context) { Tokens.ForEach(token => token.Verify(context)); }