Ejemplo n.º 1
0
        protected internal override bool ValidateSelfValueFromModifiedChild(PropertyEnumerator modifiedChildEnum, object value)
        {
            if (Validator != null)
            {
                if (modifiedChildEnum.Property.Value is PropertyValueSimulated)
                {
                    try
                    {
                        PropertyTypeDescriptorContext context    = GetTypeDescriptorContext(modifiedChildEnum);
                        PropertyDescriptorCollection  collection = TypeConverter.GetProperties(context, GetValue());
                        PropertyValue childValue = modifiedChildEnum.Property.Value;

                        if (collection != null)
                        {
                            IDictionary dictionary = new Hashtable(collection.Count);
                            foreach (PropertyDescriptor propertyDescriptor in collection)
                            {
                                if (modifiedChildEnum.Property.Name.Equals(propertyDescriptor.Name))
                                {
                                    if (value is string)
                                    {
                                        dictionary[propertyDescriptor.Name] = childValue.TypeConverter.ConvertFromString(
                                            context, childValue.CultureInfo, childValue.GetActualString(value as string));
                                    }
                                    else
                                    {
                                        dictionary[propertyDescriptor.Name] = value;
                                    }
                                }
                                else
                                {
                                    dictionary[propertyDescriptor.Name] = propertyDescriptor.GetValue(childValue.TargetInstance);
                                }
                            }

                            // Create the parent value from all the sibling values
                            object newParentValue = TypeConverter.CreateInstance(context, dictionary);

                            // Validate the parent value
                            PropertyEnumerator invalidPropEnum;
                            if (ValidateValue(newParentValue, out invalidPropEnum))
                            {
                                return(true);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return(false);
                    }

                    return(true);
                }
            }

            return(true);
        }