コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularExpressionRuleDescriptor" /> class.
        /// </summary>
        /// <param name="e">The e.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <exception cref="ArgumentException">propertyName cannot be null or whitespace.</exception>
        /// <exception cref="InvalidOperationException">e.CustomRegularExpressionPattern is not a valid regular expression.</exception>
        public RegularExpressionRuleDescriptor(RegularExpressionValidatorAttribute e, String propertyName)
            : base(propertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage, e.OverrideMessage)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (String.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentException("Value cannot be null or white space.", nameof(propertyName));
            }
            this.RegularExpressionPatternType = e.RegularExpressionPatternType;

            if (e.RegularExpressionPatternType == RegularExpressionPatternType.Custom)
            {
                if (!(StringValidationRules.IsRegularExpressionPatternValid(e.CustomRegularExpressionPattern)))
                {
                    throw new InvalidOperationException("e.CustomRegularExpressionPattern is not a valid regular expression.");
                }

                _customRegularExpressionPattern = e.CustomRegularExpressionPattern;
            }

            this.RequiredEntry = e.RequiredEntry;
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RegularExpressionValidatorAttribute" /> class.
 /// </summary>
 /// <param name="customRegularExpressionPattern">The custom regular expression pattern.</param>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidOperationException">customRegularExpressionPattern is not a valid regular expression.</exception>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public RegularExpressionValidatorAttribute(String customRegularExpressionPattern, RequiredEntry requiredEntry)
 {
     if (!(StringValidationRules.IsRegularExpressionPatternValid(customRegularExpressionPattern)))
     {
         throw new ArgumentOutOfRangeException(nameof(customRegularExpressionPattern), "customRegularExpressionPattern is not a valid regular expression.");
     }
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.RegularExpressionPatternType = RegularExpressionPatternType.Custom;
     this.RequiredEntry = requiredEntry;
     this.CustomRegularExpressionPattern = customRegularExpressionPattern;
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularExpressionRuleDescriptor" /> class.
        /// </summary>
        /// <param name="customRegularExpressionPattern">The custom regular expression pattern.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="customMessage">The custom message.</param>
        /// <param name="propertyFriendlyName">Name of the property friendly.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="ruleSet">The rule set.</param>
        /// <param name="overrideMessage">The override message.</param>
        /// <exception cref="InvalidOperationException">customRegularExpressionPattern is not a valid regular expression.</exception>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        public RegularExpressionRuleDescriptor(String customRegularExpressionPattern, RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
            : base(customMessage, propertyFriendlyName, propertyName, ruleSet, overrideMessage)
        {
            this.RegularExpressionPatternType = RegularExpressionPatternType.Custom;
            this.RequiredEntry = requiredEntry;

            if (!(StringValidationRules.IsRegularExpressionPatternValid(customRegularExpressionPattern)))
            {
                throw new InvalidOperationException("customRegularExpressionPattern is not a valid regular expression.");
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }

            _customRegularExpressionPattern = customRegularExpressionPattern;
        }