Exemplo n.º 1
0
        /// <summary>
        /// Validates the  to check whether it is a <see cref="ScalarParameterType"/>
        /// </summary>
        /// <param name="quantityKind">
        /// A <see cref="QuantityKind"/>
        /// </param>
        /// <param name="scale">
        /// The <see cref="MeasurementScale"/>
        /// </param>
        /// <param name="value">
        /// the string representation of a <see cref="ScalarParameterType"/> value
        /// </param>
        /// <returns>
        /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message.
        /// </returns>
        public static ValidationResult Validate(this QuantityKind quantityKind, MeasurementScale scale, string value)
        {
            ValidationResult result;

            if (value == DefaultValue)
            {
                result.ResultKind = ValidationResultKind.Valid;
                result.Message    = string.Empty;
                return(result);
            }

            result = scale.Validate(value);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates the  to check whether it is a <see cref="ScalarParameterType"/>
        /// </summary>
        /// <param name="quantityKind">
        /// A <see cref="QuantityKind"/>
        /// </param>
        /// <param name="scale">
        /// The <see cref="MeasurementScale"/>
        /// </param>
        /// <param name="value">
        /// The value that is to be validated.
        /// </param>
        /// <param name="provider">
        /// The <see cref="IFormatProvider"/> used to validate, if set to null <see cref="CultureInfo.CurrentCulture"/> will be used.
        /// </param>
        /// <returns>
        /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message.
        /// </returns>
        public static ValidationResult Validate(this QuantityKind quantityKind, MeasurementScale scale, object value, IFormatProvider provider = null)
        {
            ValidationResult result;

            if (scale == null)
            {
                Logger.Error("The scale is null with a quantity kind as the parameter type.");
                result.ResultKind = ValidationResultKind.Invalid;
                result.Message    = "The scale is null with a quantity kind as the parameter type.";
                return(result);
            }

            var stringValue = value as string;

            if (stringValue != null && stringValue == DefaultValue)
            {
                result.ResultKind = ValidationResultKind.Valid;
                result.Message    = string.Empty;
                return(result);
            }

            result = scale.Validate(value, provider);
            return(result);
        }