当前位置: 首页>>代码示例>>C#>>正文


C# PropertyRule类代码示例

本文整理汇总了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;
        }
开发者ID:Galilyou,项目名称:FluentValidation,代码行数:14,代码来源:DefaultValidatorSelector.cs

示例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;
        }
开发者ID:sarge,项目名称:FluentValidation,代码行数:14,代码来源:RulesetValidatorSelector.cs

示例3: PropertyValidatorContext

		public PropertyValidatorContext(ValidationContext parentContext, PropertyRule rule, string propertyName, object propertyValue)
		{
			ParentContext = parentContext;
			Rule = rule;
			PropertyName = propertyName;
			propertyValueContainer = new Lazy<object>(() => propertyValue);
		}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:7,代码来源:PropertyValidatorContext.cs

示例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);
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:11,代码来源:RegularExpressionAdapter.cs

示例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));
 }
开发者ID:Borzoo,项目名称:Nancy,代码行数:11,代码来源:FallbackAdapter.cs

示例6: PropertyValidatorContext

 public PropertyValidatorContext(ValidationContext parentContext, PropertyRule rule, string propertyName)
 {
     ParentContext = parentContext;
     Rule = rule;
     PropertyName = propertyName;
     propertyValueContainer = new Lazy<object>(() => rule.PropertyFunc(parentContext.InstanceToValidate));
 }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:7,代码来源:PropertyValidatorContext.cs

示例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);
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:12,代码来源:LengthAdapter.cs

示例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);
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:12,代码来源:LessThanAdapter.cs

示例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;
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:8,代码来源:Properties.cs

示例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());
     };
 }
开发者ID:jbattermann,项目名称:Nancy,代码行数:13,代码来源:AdapterBase.cs

示例12: SimpleUnitaryClientSideValidator

 public SimpleUnitaryClientSideValidator(ModelMetadata metadata,
                                         ControllerContext controllerContext,
                                         PropertyRule rule,
                                         IPropertyValidator validator,
                                         string validationType)
     : base(metadata, controllerContext, rule, validator)
 {
     _validationType = validationType;
 }
开发者ID:Gwayaboy,项目名称:MVCSolutionSample,代码行数:9,代码来源:SimpleUnitaryClientSideValidator.cs

示例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;
 }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:15,代码来源:PropertyValidatorContext.cs

示例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;
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:9,代码来源:OnlyCharactersValidatorTest.cs

示例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);
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:10,代码来源:StandalonePropertyValidationTester.cs


注:本文中的PropertyRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。