/// <summary>
        /// Initializes a new instance of the <see cref="CustomExternalComponentValidatorAttribute"/> class.
        /// </summary>
        /// <param name="targetComponentType"><see cref="Type"/> of the component containing the property to be validated. This type must implement <see cref="GeneticComponent"/>.</param>
        /// <param name="validatorType"><see cref="Type"/> of validator for the configuration property. This
        /// type must derive from <see cref="ComponentValidator"/>.</param>
        /// <param name="validatorConstructorArguments">
        /// The arguments to pass to the constructor the associated <see cref="ComponentValidator"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="validatorType"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="targetComponentType"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetComponentType"/> does not implement <see cref="GeneticComponent"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="validatorType"/> does not derive from <see cref="PropertyValidator"/>.</exception>
        public CustomExternalComponentValidatorAttribute(Type targetComponentType, Type validatorType, params object[] validatorConstructorArguments)
            : base(validatorType, validatorConstructorArguments)
        {
            ExternalValidatorAttributeHelper.ValidateArguments(targetComponentType);

            this.TargetComponentType = targetComponentType;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegerExternalValidatorAttribute"/> class.
        /// </summary>
        /// <param name="targetComponentType"><see cref="Type"/> of the component containing the property to be validated. This type must implement <see cref="GeneticComponent"/>.</param>
        /// <param name="targetPropertyName">Property of the <paramref name="targetComponentType"/> to be validated.</param>
        /// <exception cref="ArgumentNullException"><paramref name="targetComponentType"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> is null or empty.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetComponentType"/> does not implement <see cref="GeneticComponent"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> does not exist on <paramref name="targetComponentType"/>.</exception>
        public IntegerExternalValidatorAttribute(Type targetComponentType, string targetPropertyName)
        {
#pragma warning disable CA1062 // Validate arguments of public methods
            ExternalValidatorAttributeHelper.ValidateArguments(targetComponentType, targetPropertyName);
#pragma warning restore CA1062 // Validate arguments of public methods

            this.TargetComponentType = targetComponentType;
            this.TargetPropertyName  = targetPropertyName;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegerExternalValidatorAttribute"/> class.
        /// </summary>
        /// <param name="targetComponentType"><see cref="Type"/> of the component containing the property to be validated. This type must derive from <see cref="GeneticComponent"/>.</param>
        /// <param name="targetPropertyName">Property of the <paramref name="targetComponentType"/> to be validated.</param>
        /// <param name="requiredValue">The boolean value that the property must have.</param>
        /// <exception cref="ArgumentNullException"><paramref name="targetComponentType"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> is null or empty.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetComponentType"/> does not implement <see cref="GeneticComponent"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> does not exist on <paramref name="targetComponentType"/>.</exception>
        public BooleanExternalValidatorAttribute(Type targetComponentType, string targetPropertyName, bool requiredValue)
            : base(requiredValue)
        {
#pragma warning disable CA1062 // Validate arguments of public methods
            ExternalValidatorAttributeHelper.ValidateArguments(targetComponentType, targetPropertyName);
#pragma warning restore CA1062 // Validate arguments of public methods

            this.TargetComponentType = targetComponentType;
            this.TargetPropertyName  = targetPropertyName;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomExternalPropertyValidatorAttribute"/> class.
        /// </summary>
        /// <param name="targetComponentType"><see cref="Type"/> of the component containing the property to be validated. This type must implement <see cref="GeneticComponent"/>.</param>
        /// <param name="targetPropertyName">Property of the <paramref name="targetComponentType"/> to be validated.</param>
        /// <param name="validatorType"><see cref="Type"/> of validator for the configuration property. This
        /// type must derive from <see cref="PropertyValidator"/>.</param>
        /// <param name="validatorConstructorArguments">
        /// The arguments to pass to the constructor the associated <see cref="ComponentValidator"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="validatorType"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="targetComponentType"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> is null or empty.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetComponentType"/> does not implement <see cref="GeneticComponent"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetPropertyName"/> does not exist on <paramref name="targetComponentType"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="validatorType"/> does not derive from <see cref="PropertyValidator"/>.</exception>
        public CustomExternalPropertyValidatorAttribute(Type targetComponentType, string targetPropertyName, Type validatorType, params object[] validatorConstructorArguments)
            : base(validatorType, validatorConstructorArguments)
        {
#pragma warning disable CA1062 // Validate arguments of public methods
            ExternalValidatorAttributeHelper.ValidateArguments(targetComponentType, targetPropertyName);
#pragma warning restore CA1062 // Validate arguments of public methods

            this.TargetComponentType = targetComponentType;
            this.TargetPropertyName  = targetPropertyName;
        }
        /// <summary>
        /// Validates that the arguments are correctly set.
        /// </summary>
        /// <param name="targetComponentType"><see cref="Type"/> of the component configuration containing the property to be validated.</param>
        /// <param name="targetProperty">Property of the <paramref name="targetComponentType"/> to be validated.</param>
        /// <exception cref="ArgumentNullException"><paramref name="targetComponentType"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetProperty"/> is null or empty.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetComponentType"/> does not implement <see cref="GeneticComponent"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="targetProperty"/> does not exist on <paramref name="targetComponentType"/>.</exception>
        public static void ValidateArguments(Type targetComponentType, string targetProperty)
        {
            ExternalValidatorAttributeHelper.ValidateArguments(targetComponentType);

            if (String.IsNullOrEmpty(targetProperty))
            {
                throw new ArgumentException(Resources.ErrorMsg_StringNullOrEmpty, nameof(targetProperty));
            }

            if (ExternalValidatorAttributeHelper.GetTargetPropertyInfo(targetComponentType, targetProperty) == null)
            {
                throw new ArgumentException(StringUtil.GetFormattedString(
                                                Resources.ErrorMsg_ExternalValidator_PropertyDoesNotExist, targetProperty, targetComponentType.FullName), nameof(targetProperty));
            }
        }