/// <summary>
 /// Initializes a new instance of the <see cref="ComparePropertyRuleDescriptor"/> class.
 /// </summary>
 /// <param name="comparisonType">Type of the comparison.</param>
 /// <param name="compareToPropertyName">Name of the compare to property.</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>
 public ComparePropertyRuleDescriptor(ComparisonType comparisonType, String compareToPropertyName, RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
     : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
 {
     this.ComparisonType        = comparisonType;
     this.CompareToPropertyName = compareToPropertyName;
     this.RequiredEntry         = requiredEntry;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ComparePropertyRuleDescriptor"/> class.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="propertyName">Name of the property.</param>
 public ComparePropertyRuleDescriptor(ComparePropertyValidatorAttribute e, String propertyName)
     : base(propertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage, e.OverrideMessage)
 {
     this.ComparisonType        = e.ComparisonType;
     this.CompareToPropertyName = e.CompareToPropertyName;
     this.RequiredEntry         = e.RequiredEntry;
 }
        /// <summary>
        /// There is some restriction on the data types that can be used as attribute parameters.
        /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type.
        /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters.
        /// </summary>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <param name="compareToValue">The compare to value.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="convertToType">Type of the convert to.</param>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">comparisonType is not a member of ComparisonType enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">convertToType is not a member of ConvertToType enum.</exception>
        public CompareValueValidatorAttribute(ComparisonType comparisonType, String compareToValue, RequiredEntry requiredEntry, ConvertToType convertToType)
        {
            if (!Enum.IsDefined(typeof(ComparisonType), comparisonType))
            {
                throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }
            if (!Enum.IsDefined(typeof(ConvertToType), convertToType))
            {
                throw new InvalidEnumArgumentException(nameof(convertToType), (Int32)convertToType, typeof(ConvertToType));
            }

            this.ComparisonType = comparisonType;

            switch (convertToType)
            {
            case ConvertToType.Date:
                this.CompareToValue = Convert.ToDateTime(compareToValue);

                break;

            case ConvertToType.Decimal:
                this.CompareToValue = Convert.ToDecimal(compareToValue);

                break;
            }

            this.RequiredEntry = requiredEntry;
        }
Ejemplo n.º 4
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;
        }
 /// <summary>Initializes a new instance of the <see cref="BankRoutingNumberValidatorAttribute"/> class.</summary>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidEnumArgumentException">Thrown when enum value requiredEntry is not defined.</exception>
 public BankRoutingNumberValidatorAttribute(RequiredEntry requiredEntry = RequiredEntry.Yes)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     base.RequiredEntry = requiredEntry;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardNumberValidatorAttribute" /> class.
 /// </summary>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public CreditCardNumberValidatorAttribute(RequiredEntry requiredEntry)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.RequiredEntry = requiredEntry;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="USStateAbbreviationValidatorAttribute"/> class.
 /// </summary>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidEnumArgumentException">Thrown when enum value requiredEntry is not defined.</exception>
 public USStateAbbreviationValidatorAttribute(RequiredEntry requiredEntry = RequiredEntry.Yes)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     base.RequiredEntry = requiredEntry;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateAbbreviationValidatorAttribute"/> class.
 /// </summary>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public StateAbbreviationValidatorAttribute(RequiredEntry requiredEntry)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.RequiredEntry = requiredEntry;
     this.ValidateForUnitedStatesOnly = ValidateUnitedStatesOnly.No;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardNumberRuleDescriptor" /> class.
 /// </summary>
 /// <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="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public CreditCardNumberRuleDescriptor(RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
     : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.RequiredEntry = requiredEntry;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularExpressionRuleDescriptor"/> class.
        /// </summary>
        /// <param name="regularExpressionPatternType">Type of the 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>
        public RegularExpressionRuleDescriptor(RegularExpressionPatternType regularExpressionPatternType, RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
            : base(customMessage, propertyFriendlyName, propertyName, ruleSet, overrideMessage)
        {
            if (regularExpressionPatternType == RegularExpressionPatternType.Custom)
            {
                throw new InvalidOperationException(Resources.RegularExpressionRuleDescriptor_RegularExpressionRuleDescriptor_This_constructor_does_not_support_assigning_the_RegularExpressionPatternType_to_Custom___Use_other_constructor_);
            }

            this.RegularExpressionPatternType = regularExpressionPatternType;
            this.RequiredEntry = requiredEntry;
        }
Ejemplo n.º 11
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>
        public RegularExpressionValidatorAttribute(String customRegularExpressionPattern, RequiredEntry requiredEntry)
        {
            this.RegularExpressionPatternType = RegularExpressionPatternType.Custom;
            this.RequiredEntry = requiredEntry;

            if (!(StringValidationRules.IsRegularExpressionPatternValid(customRegularExpressionPattern)))
            {
                throw new ArgumentOutOfRangeException("customRegularExpressionPattern", Resources.RegularExpressionValidatorAttribute_RegularExpressionValidatorAttribute_Programmer_did_not_supply_a_valid_CustomRegularExpressionPattern);
            }

            this.CustomRegularExpressionPattern = customRegularExpressionPattern;
        }
        /// <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>
        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(Resources.RegularExpressionRuleDescriptor_CustomRegularExpressionPattern_value_is_not_a_valid_regular_expression_);
            }

            _customRegularExpressionPattern = customRegularExpressionPattern;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardNumberRuleDescriptor" /> class.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <exception cref="ArgumentNullException">e is null.</exception>
 /// <exception cref="ArgumentException">propertyName cannot be null or whitespace.</exception>
 public CreditCardNumberRuleDescriptor(CreditCardNumberValidatorAttribute 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.RequiredEntry = e.RequiredEntry;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompareValueValidatorAttribute" /> class.
 /// </summary>
 /// <param name="comparisonType">Type of the comparison.</param>
 /// <param name="compareToValue">The compare to value.</param>
 /// <param name="requiredEntry">The required entry.</param>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 /// <exception cref="InvalidEnumArgumentException">comparisonType is not a member of ComparisonType enum.</exception>
 public CompareValueValidatorAttribute(ComparisonType comparisonType, Int32 compareToValue, RequiredEntry requiredEntry)
 {
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     if (!Enum.IsDefined(typeof(ComparisonType), comparisonType))
     {
         throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType));
     }
     this.ComparisonType = comparisonType;
     this.CompareToValue = compareToValue;
     this.RequiredEntry  = requiredEntry;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainRuleDescriptor" /> class.
 /// </summary>
 /// <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>
 /// <param name="data">The data.</param>
 /// <exception cref="ArgumentNullException">data is null.</exception>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public DomainRuleDescriptor(RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage, params String[] data)
     : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.Data          = data;
     this.RequiredEntry = requiredEntry;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainValidatorAttribute" /> class.
 /// </summary>
 /// <param name="requiredEntry">The required entry.</param>
 /// <param name="data">The data. Is a param array of strings separated by a comma that represents each valid value in the domain.</param>
 /// <exception cref="ArgumentNullException">data is null.</exception>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 /// <example>
 /// If valid values are Slide, Fade and None then the attribute signature would be:  "Slide", "Fade", "None"
 /// <code>
 /// [DomainValidator(RequiredEntry.Yes, "Slide", "Fade", "None")]
 /// </code></example>
 public DomainValidatorAttribute(RequiredEntry requiredEntry, params String[] data)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.RequiredEntry = requiredEntry;
     this.Data          = new String[data.Length];
     data.CopyTo(this.Data, 0);
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularExpressionValidatorAttribute"/> class.
        /// </summary>
        /// <param name="regularExpressionPatternType">Type of the regular expression pattern.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">regularExpressionPatternType is not member of RegularExpressionPatternType enum.</exception>
        public RegularExpressionValidatorAttribute(RegularExpressionPatternType regularExpressionPatternType, RequiredEntry requiredEntry)
        {
            if (!Enum.IsDefined(typeof(RegularExpressionPatternType), regularExpressionPatternType))
            {
                throw new InvalidEnumArgumentException(nameof(regularExpressionPatternType), (Int32)regularExpressionPatternType, typeof(RegularExpressionPatternType));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }

            this.RegularExpressionPatternType = regularExpressionPatternType;
            this.RequiredEntry = requiredEntry;
        }
        /// <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>
        public RegularExpressionRuleDescriptor(RegularExpressionValidatorAttribute e, String propertyName)
            : base(propertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage, e.OverrideMessage)
        {
            this.RegularExpressionPatternType = e.RegularExpressionPatternType;

            if (e.RegularExpressionPatternType == RegularExpressionPatternType.Custom)
            {
                if (!(StringValidationRules.IsRegularExpressionPatternValid(e.CustomRegularExpressionPattern)))
                {
                    throw new InvalidOperationException(Resources.RegularExpressionRuleDescriptor_CustomRegularExpressionPattern_value_is_not_a_valid_regular_expression_);
                }

                _customRegularExpressionPattern = e.CustomRegularExpressionPattern;
            }

            this.RequiredEntry = e.RequiredEntry;
        }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularExpressionRuleDescriptor" /> class.
        /// </summary>
        /// <param name="regularExpressionPatternType">Type of the 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">This constructor does not support assigning the RegularExpressionPatternType to Custom.  Use other constructor.</exception>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">regularExpressionPatternType is not member of RegularExpressionPatternType enum.</exception>
        public RegularExpressionRuleDescriptor(RegularExpressionPatternType regularExpressionPatternType, RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
            : base(customMessage, propertyFriendlyName, propertyName, ruleSet, overrideMessage)
        {
            if (regularExpressionPatternType == RegularExpressionPatternType.Custom)
            {
                throw new InvalidOperationException("This constructor does not support assigning the RegularExpressionPatternType to Custom.  Use other constructor.");
            }
            if (!Enum.IsDefined(typeof(RegularExpressionPatternType), regularExpressionPatternType))
            {
                throw new InvalidEnumArgumentException(nameof(regularExpressionPatternType), (Int32)regularExpressionPatternType, typeof(RegularExpressionPatternType));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }

            this.RegularExpressionPatternType = regularExpressionPatternType;
            this.RequiredEntry = requiredEntry;
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComparePropertyRuleDescriptor" /> class.
 /// </summary>
 /// <param name="comparisonType">Type of the comparison.</param>
 /// <param name="compareToPropertyName">Name of the compare to property.</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="InvalidEnumArgumentException">comparisonType is not member of ComparisonType enum.</exception>
 /// <exception cref="ArgumentException">compareToPropertyName cannot be null or whitespace.</exception>
 /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
 public ComparePropertyRuleDescriptor(ComparisonType comparisonType, String compareToPropertyName, RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
     : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
 {
     if (!Enum.IsDefined(typeof(ComparisonType), comparisonType))
     {
         throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType));
     }
     if (String.IsNullOrWhiteSpace(compareToPropertyName))
     {
         throw new ArgumentException("Value cannot be null or white space.", nameof(compareToPropertyName));
     }
     if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
     {
         throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
     }
     this.ComparisonType        = comparisonType;
     this.CompareToPropertyName = compareToPropertyName;
     this.RequiredEntry         = requiredEntry;
 }
Ejemplo n.º 23
0
        /// <summary>Initializes a new instance of the <see cref="DomainValidatorAttribute"/> class.</summary>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="data">The data is a param array of strings separated by a comma that represent each valid value in the domain.</param>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value requiredEntry is not defined.</exception>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when domain does not have at least one value.</exception>
        /// <example>
        /// If valid values are Top, Bottom, Right and Left then the attribute signature would be:  "Top", "Bottom", "Right", "Left"
        ///     <code>
        ///         [DomainValidator(RequiredEntry.Yes, "Top", "Bottom", "Right", "Left")]
        ///     </code>
        ///     <code>
        ///         [DomainValidator(RequiredEntry.No, "Top", "Bottom", "Right", "Left")]
        ///     </code>
        ///     <code>
        ///         [DomainValidator("Top", "Bottom", "Right", "Left")]
        ///     </code>
        /// </example>
        public DomainValidatorAttribute(RequiredEntry requiredEntry, params String[] data)
        {
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == Zero)
            {
                throw new InvalidOperationException($"{nameof(data)} is empty, must have at least one value.");
            }

            this.RequiredEntry = requiredEntry;
            this.Data          = new String[data.Length];
            data.CopyTo(this.Data, Zero);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComparePropertyValidatorAttribute" /> class.
        /// </summary>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <param name="compareToPropertyName">Name of the compare to property.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        /// <exception cref="ArgumentException">compareToPropertyName cannot be null or whitespace.</exception>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        public ComparePropertyValidatorAttribute(ComparisonType comparisonType, String compareToPropertyName, RequiredEntry requiredEntry)
        {
            if (!Enum.IsDefined(typeof(ComparisonType), comparisonType))
            {
                throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType));
            }
            if (String.IsNullOrWhiteSpace(compareToPropertyName))
            {
                throw new ArgumentException("Value cannot be null or white space.", nameof(compareToPropertyName));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }

            this.ComparisonType        = comparisonType;
            this.CompareToPropertyName = compareToPropertyName;
            this.RequiredEntry         = requiredEntry;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompareValueRuleDescriptor" /> class.
        /// </summary>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="compareToValue">The compare to value.</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="ArgumentNullException">compareToValue is null.</exception>
        /// <exception cref="InvalidEnumArgumentException">comparisonType is not member of ComparisonType enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        public CompareValueRuleDescriptor(ComparisonType comparisonType, RequiredEntry requiredEntry, IComparable compareToValue, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
            : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
        {
            if (compareToValue == null)
            {
                throw new ArgumentNullException(nameof(compareToValue));
            }
            if (!Enum.IsDefined(typeof(ComparisonType), comparisonType))
            {
                throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }

            this.ComparisonType = comparisonType;
            this.CompareToValue = compareToValue;
            this.RequiredEntry  = requiredEntry;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RangeRuleDescriptor" /> class.
        /// </summary>
        /// <param name="lowerRangeBoundaryType">Type of the lower range boundary.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="upperRangeBoundaryType">Type of the upper range boundary.</param>
        /// <param name="lowerValue">The lower value.</param>
        /// <param name="upperValue">The upper value.</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="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">lowerRangeBoundaryType is not member of RangeBoundaryType enum.</exception>
        /// <exception cref="InvalidEnumArgumentException">upperRangeBoundaryType is not member of RangeBoundaryType enum.</exception>
        public RangeRuleDescriptor(RangeBoundaryType lowerRangeBoundaryType, RequiredEntry requiredEntry, RangeBoundaryType upperRangeBoundaryType, IComparable lowerValue, IComparable upperValue, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
            : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
        {
            if (!Enum.IsDefined(typeof(RangeBoundaryType), lowerRangeBoundaryType))
            {
                throw new InvalidEnumArgumentException(nameof(lowerRangeBoundaryType), (Int32)lowerRangeBoundaryType, typeof(RangeBoundaryType));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }
            if (!Enum.IsDefined(typeof(RangeBoundaryType), upperRangeBoundaryType))
            {
                throw new InvalidEnumArgumentException(nameof(upperRangeBoundaryType), (Int32)upperRangeBoundaryType, typeof(RangeBoundaryType));
            }

            this.LowerRangeBoundaryType = lowerRangeBoundaryType;
            this.RequiredEntry          = requiredEntry;
            this.UpperRangeBoundaryType = upperRangeBoundaryType;
            this.LowerValue             = lowerValue;
            this.UpperValue             = upperValue;
        }
        /// <summary>
        /// HACK - New Feature - fixed constructor to support date and decimal types since these are not allowed in a attributes constructor
        /// There is some restriction on the data types that can be used as attribute parameters.
        /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type.
        /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters.
        /// </summary>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <param name="compareToValue">The compare to value.</param>
        /// <param name="requiredEntry">The required entry.</param>
        /// <param name="convertToType">Type of the convert to.</param>
        public CompareValueValidatorAttribute(ComparisonType comparisonType, String compareToValue, RequiredEntry requiredEntry, ConvertToType convertToType)
        {
            this.ComparisonType = comparisonType;

            switch (convertToType)
            {
            case ConvertToType.Date:
                this.CompareToValue = Convert.ToDateTime(compareToValue);

                break;

            case ConvertToType.Decimal:
                this.CompareToValue = Convert.ToDecimal(compareToValue);

                break;

            default:
                throw new OverflowException(String.Format(Resources.CompareValueValidatorAttribute_CompareValueValidatorAttribute_This_ConvertToType_has_not_yet_been_programmed__value_passed_was___0_FomatString, convertToType));
            }

            this.RequiredEntry = requiredEntry;
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardNumberRuleDescriptor"/> class.
 /// </summary>
 /// <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>
 public CreditCardNumberRuleDescriptor(RequiredEntry requiredEntry, String customMessage, String propertyFriendlyName, String propertyName, String ruleSet, String overrideMessage)
     : base(propertyName, propertyFriendlyName, ruleSet, customMessage, overrideMessage)
 {
     this.RequiredEntry = requiredEntry;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardNumberRuleDescriptor"/> class.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="propertyName">Name of the property.</param>
 public CreditCardNumberRuleDescriptor(CreditCardNumberValidatorAttribute e, String propertyName)
     : base(propertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage, e.OverrideMessage)
 {
     this.RequiredEntry = e.RequiredEntry;
 }
Ejemplo n.º 30
0
        /// <summary>Initializes a new instance of the <see cref="PasswordValidatorAttribute"/> class.</summary>
        /// <param name="lowerCaseCharacter">Is a lower case character required.</param>
        /// <param name="upperCaseCharacter">Is an upper case character required.</param>
        /// <param name="digitCharacter">Is a digit character required.</param>
        /// <param name="specialCharacter">Is a special character required.</param>
        /// <param name="requiredEntry">Is the entry required.</param>
        /// <param name="allowedPasswordSpecialCharacters">The allowed password special characters. Change value to limit or increase the number of special characters.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when minimumLength is less than one.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when maximumLength is less than one.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when maximumLength less than or equal to Minimum Length.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value lowerCaseCharacter is not defined.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value upperCaseCharacter is not defined.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value digitCharacter is not defined.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value specialCharacter is not defined.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when enum value requiredEntry is not defined.</exception>
        /// <exception cref="ArgumentNullEmptyWhiteSpaceException">Thrown when allowedPasswordSpecialCharacters is null, empty, or white space.</exception>
        public PasswordValidatorAttribute(Int32 minimumLength, Int32 maximumLength, LowerCaseCharacter lowerCaseCharacter, UpperCaseCharacter upperCaseCharacter, DigitCharacter digitCharacter, SpecialCharacter specialCharacter, RequiredEntry requiredEntry, String allowedPasswordSpecialCharacters = "!@#$*&^%()-_+|")
        {
            if (minimumLength < One)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumLength), Strings.MustBeGreaterThanZero);
            }
            if (maximumLength < One)
            {
                throw new ArgumentOutOfRangeException(nameof(maximumLength), Strings.MustBeGreaterThanZero);
            }
            if (maximumLength < minimumLength)
            {
                throw new ArgumentOutOfRangeException(nameof(maximumLength), Strings.MustBeGreaterThanOrEqualToMinimumLength);
            }
            if (!Enum.IsDefined(typeof(LowerCaseCharacter), lowerCaseCharacter))
            {
                throw new InvalidEnumArgumentException(nameof(lowerCaseCharacter), (Int32)lowerCaseCharacter, typeof(LowerCaseCharacter));
            }
            if (!Enum.IsDefined(typeof(UpperCaseCharacter), upperCaseCharacter))
            {
                throw new InvalidEnumArgumentException(nameof(upperCaseCharacter), (Int32)upperCaseCharacter, typeof(UpperCaseCharacter));
            }
            if (!Enum.IsDefined(typeof(DigitCharacter), digitCharacter))
            {
                throw new InvalidEnumArgumentException(nameof(digitCharacter), (Int32)digitCharacter, typeof(DigitCharacter));
            }
            if (!Enum.IsDefined(typeof(SpecialCharacter), specialCharacter))
            {
                throw new InvalidEnumArgumentException(nameof(specialCharacter), (Int32)specialCharacter, typeof(SpecialCharacter));
            }
            if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry))
            {
                throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry));
            }
            if (specialCharacter == SpecialCharacter.Yes && String.IsNullOrWhiteSpace(allowedPasswordSpecialCharacters))
            {
                throw new ArgumentNullEmptyWhiteSpaceException(nameof(allowedPasswordSpecialCharacters));
            }

            this.MinimumLength      = minimumLength;
            this.MaximumLength      = maximumLength;
            this.LowerCaseCharacter = lowerCaseCharacter;
            this.UpperCaseCharacter = upperCaseCharacter;
            this.DigitCharacter     = digitCharacter;
            this.SpecialCharacter   = specialCharacter;
            this.AllowedPasswordSpecialCharacters = allowedPasswordSpecialCharacters;
            this.RequiredEntry = requiredEntry;
        }