本文整理汇总了C#中FluentValidation.Validators.PropertyValidatorContext类的典型用法代码示例。如果您正苦于以下问题:C# PropertyValidatorContext类的具体用法?C# PropertyValidatorContext怎么用?C# PropertyValidatorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyValidatorContext类属于FluentValidation.Validators命名空间,在下文中一共展示了PropertyValidatorContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetComparisonValue
private IComparable GetComparisonValue(PropertyValidatorContext context) {
if(valueToCompareFunc != null) {
return (IComparable)valueToCompareFunc(context.Instance);
}
return (IComparable)ValueToCompare;
}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:7,代码来源:AbstractComparisonValidator.cs
示例2: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue != null)
return (bool)context.PropertyValue;
return false;
}
开发者ID:netsouls,项目名称:eCentral,代码行数:7,代码来源:IsCheckedPropertyValidator.cs
示例3: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
bool fail = false;
string stringTarget = Convert.ToString(context.PropertyValue);
switch (typeName)
{
case ValidatableTypes.number:
re = new Regex(@"^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$");
break;
case ValidatableTypes.email:
re = new Regex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$");
break;
case ValidatableTypes.date:
DateTime d;
fail = !DateTime.TryParse(stringTarget, out d);
break;
case ValidatableTypes.dateISO:
re = new Regex(@"^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$");
break;
case ValidatableTypes.digits:
re = new Regex(@"^\d+$");
break;
case ValidatableTypes.url:
re = new Regex(@"^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$");
break;
}
if (re != null)
fail = !re.IsMatch(stringTarget);
return !fail;
}
开发者ID:rsmolnikov,项目名称:FluentValidation,代码行数:31,代码来源:TypeValidator.cs
示例4: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
var value = context.PropertyValue as string;
if (String.IsNullOrEmpty(value))
return false;
return value.Length == 24;
}
开发者ID:Nangal,项目名称:Exceptionless,代码行数:7,代码来源:IsObjectIdValidator.cs
示例5: Validate
public override IEnumerable<ValidationFailure> Validate(PropertyValidatorContext context)
{
if (context.Rule.Member == null) {
throw new InvalidOperationException(string.Format("Nested validators can only be used with Member Expressions."));
}
var collection = context.PropertyValue as IEnumerable;
if (collection == null) {
yield break;
}
int count = 0;
foreach (var element in collection) {
if(element == null) {
// If an element in the validator is null then we want to skip it to prevent NullReferenceExceptions in the child validator.
// We still need to update the counter to ensure the indexes are correct.
count++;
continue;
}
var newContext = context.ParentContext.CloneForChildValidator(element);
newContext.PropertyChain.Add(context.Rule.Member);
newContext.PropertyChain.AddIndexer(count++);
var results = childValidator.Validate(newContext).Errors;
foreach (var result in results) {
yield return result;
}
}
}
开发者ID:chilversc,项目名称:FluentValidation,代码行数:34,代码来源:ChildCollectionValidatorAdaptor.cs
示例6: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
if (context.PropertyValue == null) return true;
var min = Min;
var max = Max;
if (MaxFunc != null && MinFunc != null)
{
max = MaxFunc(context.Instance);
min = MinFunc(context.Instance);
}
int length = context.PropertyValue.ToString().Length;
if (length < min || (length > max && max != -1)) {
context.MessageFormatter
.AppendArgument("MinLength", min)
.AppendArgument("MaxLength", max)
.AppendArgument("TotalLength", length);
return false;
}
return true;
}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:25,代码来源:LengthValidator.cs
示例7: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
var value = context.PropertyValue as string;
if (value == null) {
return true;
}
value = value.Replace("-", "").Replace(" ", "");
int checksum = 0;
bool evenDigit = false;
// http://www.beachnet.com/~hstiles/cardtype.html
foreach (char digit in value.ToCharArray().Reverse()) {
if (!char.IsDigit(digit)) {
return false;
}
int digitValue = (digit - '0') * (evenDigit ? 2 : 1);
evenDigit = !evenDigit;
while (digitValue > 0) {
checksum += digitValue % 10;
digitValue /= 10;
}
}
return (checksum % 10) == 0;
}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:28,代码来源:CreditCardValidator.cs
示例8: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue != null && !regex.IsMatch((string)context.PropertyValue)) {
return false;
}
return true;
}
开发者ID:Tigraine,项目名称:FluentValidation,代码行数:7,代码来源:RegularExpressionValidator.cs
示例9: GetComparisonValue
private object GetComparisonValue(PropertyValidatorContext context) {
if(func != null) {
return func(context.Instance);
}
return ValueToCompare;
}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:7,代码来源:EqualValidator.cs
示例10: CreateNewValidationContextForChildValidator
protected ValidationContext CreateNewValidationContextForChildValidator(object instanceToValidate, PropertyValidatorContext propertyValidatorContext, IValidatorSelector validatorSelector)
{
var propertyChain = new PropertyChain(propertyValidatorContext.PropertyChain);
propertyChain.Add(propertyValidatorContext.Member);
return new ValidationContext(instanceToValidate, propertyChain, validatorSelector);
}
开发者ID:rsmolnikov,项目名称:FluentValidation,代码行数:7,代码来源:ChildValidatorAdaptor.cs
示例11: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
var ccValue = context.PropertyValue as string;
if (String.IsNullOrWhiteSpace(ccValue))
return false;
ccValue = ccValue.Replace(" ", "");
ccValue = ccValue.Replace("-", "");
int checksum = 0;
bool evenDigit = false;
//http://www.beachnet.com/~hstiles/cardtype.html
foreach (char digit in ccValue.Reverse())
{
if (!Char.IsDigit(digit))
return false;
int digitValue = (digit - '0') * (evenDigit ? 2 : 1);
evenDigit = !evenDigit;
while (digitValue > 0)
{
checksum += digitValue % 10;
digitValue /= 10;
}
}
return (checksum % 10) == 0;
}
开发者ID:muharremha,项目名称:MuhFrame,代码行数:30,代码来源:CreditCardPropertyValidator.cs
示例12: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
if (!predicate(context.Instance, context.PropertyValue, context)) {
return false;
}
return true;
}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:PredicateValidator.cs
示例13: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
#if PORTABLE40
return IsValidAsync(context, new CancellationToken()).Result;
#else
return Task.Run(() => IsValidAsync(context, new CancellationToken())).GetAwaiter().GetResult();
#endif
}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:7,代码来源:AsyncValidatorBase.cs
示例14: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) {
return false;
}
return true;
}
开发者ID:Tigraine,项目名称:FluentValidation,代码行数:7,代码来源:NotNullValidator.cs
示例15: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
if (OsInfo.IsNotWindows) return true;
if (!_runtimeInfo.IsWindowsService) return true;
var path = context.PropertyValue.ToString();
if (!DriveRegex.IsMatch(path)) return true;
var drives = _diskProvider.GetDrives();
foreach (var drive in drives)
{
if (path.StartsWith(drive.Name, StringComparison.InvariantCultureIgnoreCase))
{
if (drive.DriveType == DriveType.Network)
{
return false;
}
}
}
return true;
}
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:25,代码来源:MappedNetworkDriveValidator.cs
示例16: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
var email = context.PropertyValue.ToString();
context.MessageFormatter.AppendArgument("EmailDomain", _emailDomain);
return _regex.IsMatch(email);
}
开发者ID:Philo,项目名称:FluentValidationSample,代码行数:8,代码来源:MustBeFromDomainEmailValidator.cs
示例17: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
return false;
if (!context.PropertyValue.ToString().Contains("@"))
return false;
return true;
}
开发者ID:silverforge,项目名称:CKValidationNew,代码行数:8,代码来源:CustomEmailValidator.cs
示例18: IsValid
protected override bool IsValid(PropertyValidatorContext context)
{
IApplicationDbContext dbContext = dbContextFunction();
string emailAddress = context.PropertyValue as string;
ApplicationUser user = dbContext.Users.FirstOrDefault(u => u.Email == emailAddress);
return user == null;
}
开发者ID:cirpitch,项目名称:FluentValidationRemoteClientSideValidation,代码行数:8,代码来源:UniqueEmailValidator.cs
示例19: Validate
public virtual IEnumerable<ValidationFailure> Validate(PropertyValidatorContext context) {
if (!IsValid(context)) {
PrepareMessageFormatterForValidationError(context);
return new[] { CreateValidationError(context) };
}
return Enumerable.Empty<ValidationFailure>();
}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:8,代码来源:PropertyValidator.cs
示例20: IsValid
protected override bool IsValid(PropertyValidatorContext context) {
var value = context.PropertyValue as string;
if (String.IsNullOrEmpty(value))
return false;
ObjectId id;
return ObjectId.TryParse(context.PropertyValue as string, out id);
}
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:8,代码来源:IsObjectIdValidator.cs
注:本文中的FluentValidation.Validators.PropertyValidatorContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论