本文整理汇总了C#中PropertyRule类的典型用法代码示例。如果您正苦于以下问题:C# PropertyRule类的具体用法?C# PropertyRule怎么用?C# PropertyRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyRule类属于命名空间,在下文中一共展示了PropertyRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecute
/// <summary>
/// Determines whether or not a rule should execute.
/// </summary>
/// <param name="rule">The rule</param>
/// <param name="propertyPath">Property path (eg Customer.Address.Line1)</param>
/// <param name="context">Contextual information</param>
/// <returns>Whether or not the validator can execute.</returns>
public bool CanExecute(PropertyRule rule, string propertyPath, ValidationContext context)
{
// By default we ignore any rules part of a RuleSet.
if (!string.IsNullOrEmpty(rule.RuleSet)) return false;
return true;
}
示例2: CanExecute
/// <summary>
/// Determines whether or not a rule should execute.
/// </summary>
/// <param name="rule">The rule</param>
/// <param name="propertyPath">Property path (eg Customer.Address.Line1)</param>
/// <param name="context">Contextual information</param>
/// <returns>Whether or not the validator can execute.</returns>
public bool CanExecute(PropertyRule rule, string propertyPath, ValidationContext context)
{
if (string.IsNullOrEmpty(rule.RuleSet) && rulesetsToExecute.Length == 0) return true;
if (!string.IsNullOrEmpty(rule.RuleSet) && rulesetsToExecute.Length > 0 && rulesetsToExecute.Contains(rule.RuleSet)) return true;
return false;
}
示例3: PropertyValidatorContext
public PropertyValidatorContext(ValidationContext parentContext, PropertyRule rule, string propertyName, object propertyValue)
{
ParentContext = parentContext;
Rule = rule;
PropertyName = propertyName;
propertyValueContainer = new Lazy<object>(() => propertyValue);
}
示例4: GetRules
/// <summary>
/// Get the <see cref="ModelValidationRule"/> instances that are mapped from the fluent validation rule.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public override IEnumerable<ModelValidationRule> GetRules(PropertyRule rule, IPropertyValidator validator)
{
yield return new RegexValidationRule(
FormatMessage(rule, validator),
GetMemberNames(rule),
((IRegularExpressionValidator)validator).Expression);
}
示例5: GetRules
/// <summary>
/// Get the <see cref="ModelValidationRule"/> instances that are mapped from the fluent validation rule.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public override IEnumerable<ModelValidationRule> GetRules(PropertyRule rule, IPropertyValidator validator)
{
yield return new ModelValidationRule(
"Custom",
base.FormatMessage(rule, validator),
base.GetMemberNames(rule));
}
示例6: PropertyValidatorContext
public PropertyValidatorContext(ValidationContext parentContext, PropertyRule rule, string propertyName)
{
ParentContext = parentContext;
Rule = rule;
PropertyName = propertyName;
propertyValueContainer = new Lazy<object>(() => rule.PropertyFunc(parentContext.InstanceToValidate));
}
示例7: GetRules
/// <summary>
/// Get the <see cref="ModelValidationRule"/> instances that are mapped from the fluent validation rule.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public override IEnumerable<ModelValidationRule> GetRules(PropertyRule rule, IPropertyValidator validator)
{
yield return new StringLengthValidationRule(
base.FormatMessage(rule, validator),
base.GetMemberNames(rule),
((ILengthValidator)validator).Min,
((ILengthValidator)validator).Max);
}
示例8: GetRules
/// <summary>
/// Get the <see cref="ModelValidationRule"/> instances that are mapped from the fluent validation rule.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public override IEnumerable<ModelValidationRule> GetRules(PropertyRule rule, IPropertyValidator validator)
{
yield return new ComparisonValidationRule(
base.FormatMessage(rule, validator),
base.GetMemberNames(rule),
ComparisonOperator.LessThan,
((LessThanValidator)validator).ValueToCompare);
}
示例9: Rule
public static PropertyRule Rule(this Func<PropertyInfo, bool> pi, out IDisposable unreg)
{
pi.AssertNotNull();
var rule = new PropertyRule(pi);
Repository.Rules.Add(rule);
unreg = new DisposableAction(() => Repository.Rules.Remove(rule));
return rule;
}
示例10: RequiredFluentValidationPropertyValidator
public RequiredFluentValidationPropertyValidator(ModelMetadata metadata, ControllerContext controllerContext, PropertyRule rule, IPropertyValidator validator)
: base(metadata, controllerContext, rule, validator)
{
bool isNonNullableValueType = !TypeAllowsNullValue(metadata.ModelType);
bool nullWasSpecified = metadata.Model == null;
ShouldValidate = isNonNullableValueType && nullWasSpecified;
}
开发者ID:henriksoerensen,项目名称:FluentValidation,代码行数:8,代码来源:RequiredFluentValidationPropertyValidator.cs
示例11: FormatMessage
/// <summary>
/// Get the formatted error message of the validator.
/// </summary>
/// <returns>A formatted error message string.</returns>
protected virtual Func<string, string> FormatMessage(PropertyRule rule, IPropertyValidator validator)
{
return displayName =>
{
return new MessageFormatter()
.AppendPropertyName(displayName ?? rule.GetDisplayName())
.BuildMessage(validator.ErrorMessageSource.GetString());
};
}
示例12: SimpleUnitaryClientSideValidator
public SimpleUnitaryClientSideValidator(ModelMetadata metadata,
ControllerContext controllerContext,
PropertyRule rule,
IPropertyValidator validator,
string validationType)
: base(metadata, controllerContext, rule, validator)
{
_validationType = validationType;
}
示例13: PropertyValidatorContext
/// <summary>
/// Constructor
/// </summary>
/// <param name="parentContext">The parent context</param>
/// <param name="rule">Property rule to apply</param>
/// <param name="propertyName">Property name</param>
public PropertyValidatorContext(
ValidationContext parentContext,
PropertyRule rule,
string propertyName)
{
ParentContext = parentContext;
Rule = rule;
PropertyName = propertyName;
}
示例14: Validate
private static IEnumerable<ValidationFailure> Validate(object value)
{
var parentContext = new ValidationContext(null);
var rule = new PropertyRule(null, x => value, null, null, typeof(string), null) { PropertyName = "Name" };
var context = new PropertyValidatorContext(parentContext, rule, null);
var validator = new OnlyCharactersValidator();
var result = validator.Validate(context);
return result;
}
示例15: Should_validate_property_value_without_instance_different_types
public void Should_validate_property_value_without_instance_different_types() {
var validator = new EqualValidator(100M); // decimal
var parentContext = new ValidationContext(null);
var rule = new PropertyRule(null, x => 100D /* double */, null, null, typeof(string), null) {
PropertyName = "Surname"
};
var context = new PropertyValidatorContext(parentContext, rule, null);
var result = validator.Validate(context); // would fail saying that decimal is not double
result.Count().ShouldEqual(0);
}