예제 #1
0
        public void SubElements()
        {
            IGetter            getter = new BasicPropertyAccessor().GetGetter(typeof(AClass), "Address");
            ClassValidator     cvadd  = new ClassValidator(typeof(Address));
            ClassValidator     cv     = new ClassValidator(typeof(AClass));
            ValidatableElement ve     = new ValidatableElement(typeof(AClass), cv);

            try
            {
                ve.AddSubElement(new ValidatableElement(typeof(Address), cvadd));
                Assert.Fail("No exception adding a subelement without getter");
            }
            catch (ArgumentException)
            {
                //ok
            }
            Assert.IsFalse(ve.HasSubElements);
            ve.AddSubElement(new ValidatableElement(typeof(Address), cvadd, getter));
            Assert.IsTrue(ve.HasSubElements);
        }
예제 #2
0
            private static void AddSubElement(Property property, ValidatableElement element)
            {
                if (property != null && property.IsComposite && !property.BackRef)
                {
                    Component component = (Component)property.Value;
                    if (component.IsEmbedded)
                    {
                        return;
                    }

                    if (property.PersistentClass != null)
                    {
                        var cv = Engine.GetClassValidator(property.PersistentClass.MappedClass);

                        if (cv != null)
                        {
                            if (cv.GetMemberConstraints(property.Name).OfType <ValidAttribute>().Any())
                            {
                                // the components is already marked as Valid
                                return;
                            }
                        }
                    }

                    IPropertyAccessor accesor = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Poco);

                    IGetter getter = accesor.GetGetter(element.EntityType, property.Name);

                    IClassValidator validator = Engine.GetClassValidator(getter.ReturnType);
                    if (validator != null)
                    {
                        ValidatableElement subElement = new ValidatableElement(getter.ReturnType, validator, getter);

                        foreach (Property currentProperty in component.PropertyIterator)
                        {
                            AddSubElement(currentProperty, subElement);
                        }

                        if (subElement.HasSubElements || subElement.Validator.HasValidationRules)
                        {
                            element.AddSubElement(subElement);
                        }
                    }
                }
            }