Hishop.Components.Validation/Validators/ObjectCollectionValidator.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace Hishop.Components.Validation.Validators
{
using Hishop.Components.Validation;
using Hishop.Components.Validation.Properties;
using System;
using System.Collections;
public class ObjectCollectionValidator : Validator
{
private string targetRuleset;
private Type targetType;
private Validator targetTypeValidator;
public ObjectCollectionValidator(Type targetType) : this(targetType, string.Empty)
{
}
public ObjectCollectionValidator(Type targetType, string targetRuleset) : base(null, null)
{
if (targetType == null)
{
throw new ArgumentNullException("targetType");
}
if (targetRuleset == null)
{
throw new ArgumentNullException("targetRuleset");
}
this.targetType = targetType;
this.targetRuleset = targetRuleset;
this.targetTypeValidator = ValidationFactory.CreateValidator(this.targetType, this.targetRuleset);
}
protected internal override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
if (objectToValidate != null)
{
IEnumerable enumerable = objectToValidate as IEnumerable;
if (enumerable != null)
{
foreach (object obj2 in enumerable)
{
if (obj2 != null)
{
if (this.targetType.IsAssignableFrom(obj2.GetType()))
{
this.targetTypeValidator.DoValidate(obj2, obj2, null, validationResults);
}
else
{
base.LogValidationResult(validationResults, Resources.ObjectCollectionValidatorIncompatibleElementInTargetCollection, obj2, null);
}
}
}
}
else
{
base.LogValidationResult(validationResults, Resources.ObjectCollectionValidatorTargetNotCollection, currentTarget, key);
}
}
}
后面还有 11 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
