コード例 #1
0
        private static bool TryGetConvertedValue(Property property, string value, IList<ValidationResult> errors, out object convertedValue)
        {
            convertedValue = null;
            try
            {
                convertedValue = property.ConvertFromBindableValue(value);
                return true;
            }
            catch (Exception ex)
            {
                errors.Add(new PropertyValidationResult(property, ex.Message));
            }

            return false;
        }
コード例 #2
0
        /// <summary>
        /// Validates a <see cref="ElementReferenceProperty"/>.
        /// </summary>
        /// <remarks>
        /// If the <paramref name="property"/> is required and <paramref name="value"/> is empty, the method reports a validation error.<br/>
        /// If the value cannot be resolved, the method reports a validation warning.<br/>
        /// </remarks>
        /// <param name="property">The <see cref="ElementReferenceProperty"/> that should be validated.</param>
        /// <param name="value">The value used for validation.</param>
        /// <param name="results">The collection to wich any results that occur during the validation can be added.</param>		
        protected override void ValidateCore(Property property, string value, IList<ValidationResult> results)
        {
            var referenceProperty = property as ElementReferenceProperty;
            if (referenceProperty == null) return;

            var convertedValue = property.ConvertFromBindableValue(value) as string;

            bool isMissingRequiredReference = string.IsNullOrEmpty(convertedValue) && property.IsRequired;

            if (isMissingRequiredReference || !property.SuggestedValues.Contains(convertedValue))
            {
                results.Add(new
                  PropertyValidationResult(
                      property,
                      GetMissingReferenceMessage(referenceProperty),
                      true));               
            }
        }