Hishop.Components.Validation/Validators/StringLengthValidator.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace Hishop.Components.Validation.Validators
{
using Hishop.Components.Validation;
using Hishop.Components.Validation.Properties;
using System;
using System.Globalization;
public class StringLengthValidator : ValueValidator<string>
{
private RangeChecker<int> rangeChecker;
public StringLengthValidator(int upperBound) : this(0, RangeBoundaryType.Ignore, upperBound, RangeBoundaryType.Inclusive)
{
}
public StringLengthValidator(int upperBound, bool negated) : this(0, RangeBoundaryType.Ignore, upperBound, RangeBoundaryType.Inclusive, negated)
{
}
public StringLengthValidator(int lowerBound, int upperBound) : this(lowerBound, RangeBoundaryType.Inclusive, upperBound, RangeBoundaryType.Inclusive)
{
}
public StringLengthValidator(int lowerBound, int upperBound, bool negated) : this(lowerBound, RangeBoundaryType.Inclusive, upperBound, RangeBoundaryType.Inclusive, negated)
{
}
public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType) : this(lowerBound, lowerBoundType, upperBound, upperBoundType, (string) null)
{
}
public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, bool negated) : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null, negated)
{
}
public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, string messageTemplate) : this(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, false)
{
this.rangeChecker = new RangeChecker<int>(lowerBound, lowerBoundType, upperBound, upperBoundType);
}
public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, string messageTemplate, bool negated) : base(messageTemplate, null, negated)
{
this.rangeChecker = new RangeChecker<int>(lowerBound, lowerBoundType, upperBound, upperBoundType);
}
protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
if (objectToValidate != null)
{
if (this.rangeChecker.IsInRange(objectToValidate.Length) == base.Negated)
{
base.LogValidationResult(validationResults, this.GetMessage(objectToValidate, key), currentTarget, key);
}
}
else
{
base.LogValidationResult(validationResults, this.GetMessage(objectToValidate, key), currentTarget, key);
}
}
后面还有 23 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
