• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# PropertyRule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中PropertyRule的典型用法代码示例。如果您正苦于以下问题:C# PropertyRule类的具体用法?C# PropertyRule怎么用?C# PropertyRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PropertyRule类属于命名空间,在下文中一共展示了PropertyRule类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Should_validate_property_value_without_instance

		public void Should_validate_property_value_without_instance() {
			var validator = new NotNullValidator();
			var parentContext = new ValidationContext(null);
			var rule = new PropertyRule(null, x => null, null, null, typeof(string), null) {
				PropertyName = "Surname"
			};
			var context = new PropertyValidatorContext(parentContext, rule, null);
			var result = validator.Validate(context);
			result.Single().ShouldNotBeNull();
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:10,代码来源:StandalonePropertyValidationTester.cs


示例17: Create

        /// <summary>
        /// Creates a <see cref="IFluentAdapter"/> instance based on the provided <paramref name="rule"/> and <paramref name="propertyValidator"/>.
        /// </summary>
        /// <param name="rule">The <see cref="PropertyRule"/> for which the adapter should be created.</param>
        /// <param name="propertyValidator">The <see cref="IPropertyValidator"/> for which the adapter should be created.</param>
        /// <returns>An <see cref="IFluentAdapter"/> instance.</returns>
        public IFluentAdapter Create(PropertyRule rule, IPropertyValidator propertyValidator)
        {
            Func<PropertyRule, IPropertyValidator, IFluentAdapter> factory;

            if (!factories.TryGetValue(propertyValidator.GetType(), out factory))
            {
                factory = (a, d) => new FluentAdapter("Custom", rule, propertyValidator);
            }

            return factory(rule, propertyValidator);
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:17,代码来源:DefaultFluentAdapterFactory.cs


示例18: FluentValidationPropertyValidator

		public FluentValidationPropertyValidator(ModelMetadata metadata, ControllerContext controllerContext, PropertyRule rule, IPropertyValidator validator) : base(metadata, controllerContext) {
			this.Validator = validator;

			// Build a new rule instead of the one passed in.
			// We do this as the rule passed in will not have the correct properties defined for standalone validation.
			// We also want to ensure we copy across the CustomPropertyName and RuleSet, if specified. 
			Rule = new PropertyRule(null, x => metadata.Model, null, null, metadata.ModelType, null) {
				PropertyName = metadata.PropertyName,
				DisplayName = rule == null ? null : rule.DisplayName,
				RuleSet = rule == null ? null : rule.RuleSet
			};
		}
开发者ID:CLupica,项目名称:ServiceStack,代码行数:12,代码来源:FluentValidationPropertyValidator.cs


示例19: GetModelValidator

        private ModelValidator GetModelValidator(ModelMetadata meta, IEnumerable<ModelValidatorProvider> validatorProviders, PropertyRule rule, IPropertyValidator propertyValidator)
        {
            //var type = propertyValidator.GetType();

            FluentValidationHttpModelValidationFactory factory =
                //validatorFactories
                //.Where(x => x.Key.IsAssignableFrom(type))
                //.Select(x => x.Value)
                //.FirstOrDefault()
                //??
                ((metadata, controllerContext, description, validator) => new FluentValidationHttpPropertyValidator(metadata, controllerContext, description, validator));

            return factory(meta, validatorProviders, rule, propertyValidator);
        }
开发者ID:danludwig,项目名称:danludwig,代码行数:14,代码来源:FluentValidationHttpModelValidatorProvider.cs


示例20: 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.GreaterThan,
                ((ExclusiveBetweenValidator)validator).From);

            yield return new ComparisonValidationRule(
                base.FormatMessage(rule, validator),
                base.GetMemberNames(rule),
                ComparisonOperator.LessThan,
                ((ExclusiveBetweenValidator)validator).To);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:18,代码来源:ExclusiveBetweenAdapter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PropertySet类代码示例发布时间:2022-05-24
下一篇:
C# PropertyMode类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap