Hishop.Components.Validation/Validators/SelfValidationValidator.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace Hishop.Components.Validation.Validators
{
using Hishop.Components.Validation;
using Hishop.Components.Validation.Properties;
using System;
using System.Reflection;
public class SelfValidationValidator : Validator
{
private MethodInfo methodInfo;
public SelfValidationValidator(MethodInfo methodInfo) : base(null, null)
{
if (methodInfo == null)
{
throw new ArgumentNullException("methodInfo");
}
if (typeof(void) != methodInfo.ReturnType)
{
throw new ArgumentException(Resources.ExceptionSelfValidationMethodWithInvalidSignature, "methodInfo");
}
ParameterInfo[] parameters = methodInfo.GetParameters();
if ((1 != parameters.Length) || (typeof(ValidationResults) != parameters[0].ParameterType))
{
throw new ArgumentException(Resources.ExceptionSelfValidationMethodWithInvalidSignature, "methodInfo");
}
this.methodInfo = methodInfo;
}
protected internal override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
if (objectToValidate == null)
{
base.LogValidationResult(validationResults, Resources.SelfValidationValidatorMessage, currentTarget, key);
}
else if (!this.methodInfo.DeclaringType.IsAssignableFrom(objectToValidate.GetType()))
{
base.LogValidationResult(validationResults, Resources.SelfValidationValidatorMessage, currentTarget, key);
}
else
{
try
{
this.methodInfo.Invoke(objectToValidate, new object[] { validationResults });
}
catch (Exception)
{
base.LogValidationResult(validationResults, Resources.SelfValidationMethodThrownMessage, currentTarget, key);
}
}
}
protected override string DefaultMessageTemplate
{
get
{
return null;
}
}
}
后面还有 2 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
