示例#1
0
        /// <summary>
        /// Checks whether the required condition has been met.
        /// </summary>
        /// <param name="propertyValue">The value of the property decorated with this attribute.</param>
        /// <param name="dependentPropertyValue">The value of the dependent property.</param>
        /// <returns><c>true</c> if the required condition has been met; otherwise, <c>false</c>.</returns>
        private bool Is(object propertyValue, object dependentPropertyValue)
        {
            if (PassOnNull && (propertyValue == null || dependentPropertyValue == null))
            {
                return(true);
            }

            if (FailOnNull && (propertyValue == null || dependentPropertyValue == null))
            {
                return(false);
            }

            return(ComparisonType.Compare(propertyValue, dependentPropertyValue));
        }
示例#2
0
        /// <summary>
        /// Determines whether the specified value of the object meets the condition.
        /// </summary>
        /// <param name="propertyValue">The value of the property decorated with this attribute.</param>
        /// <param name="dependentPropertyValue">The value of the dependent property.</param>
        /// <param name="container">The model this object is contained within.</param>
        /// <returns><c>true</c> if the specified value is valid; otherwise, <c>false</c>.</returns>
        protected virtual bool IsConditionMet(object propertyValue, object dependentPropertyValue, object container)
        {
            dependentPropertyValue = HandleEnumerableSelectListItem(dependentPropertyValue);

            if (PassOnNull && dependentPropertyValue == null)
            {
                return(true);
            }

            if (FailOnNull && dependentPropertyValue == null)
            {
                return(false);
            }

            var valuesToTestAgainst = DependentValue as object[] ?? new[] { DependentValue };
            var actualValues        = dependentPropertyValue as object[] ?? new[] { dependentPropertyValue };

            var result = new List <bool>();


            foreach (var dependentValue in valuesToTestAgainst)
            {
                foreach (var actualValue in actualValues)
                {
                    result.Add(ComparisonType.Compare(actualValue, dependentValue));
                }
            }
            if (ComparisonType == ComparisonType.NotEqualTo)
            {
                // Negative AND validation (all must be true)
                return(!result.Contains(false));
            }
            else
            {
                // Positive OR validation (at least one must be true)
                return(result.Contains(true));
            }
        }
示例#3
0
 /// <summary>
 /// Checks whether the required condition has been met.
 /// </summary>
 /// <param name="propertyValue">The value of the property decorated with this attribute.</param>
 /// <param name="dependentPropertyValue">The value of the dependent property.</param>
 /// <param name="valueToTestAgainst">The value to test the dependent property value against.</param>
 /// <returns><c>true</c> if the required condition has been met; otherwise, <c>false</c>.</returns>
 protected virtual bool IsConditionMet(object propertyValue, object dependentPropertyValue, object valueToTestAgainst)
 {
     return(ComparisonType.Compare(dependentPropertyValue, valueToTestAgainst));
 }