private bool HasExplicitTypeConvention(Member property)
        {
            // todo: clean this up!
            //        What it's doing is finding if there are any IUserType conventions
            //        that would be applied to this property, if there are then we should
            //        definitely automap it. The nasty part is that right now we don't have
            //        a model, so we're having to create a fake one so the convention will
            //        apply to it.
            var conventions = conventionFinder
                .Find<IPropertyConvention>()
                .Where(c =>
                {
                    if (!typeof(IUserTypeConvention).IsAssignableFrom(c.GetType()))
                        return false;

                    var criteria = new ConcreteAcceptanceCriteria<IPropertyInspector>();
                    var acceptance = c as IConventionAcceptance<IPropertyInspector>;
                    
                    if (acceptance != null)
                        acceptance.Accept(criteria);

                    return criteria.Matches(new PropertyInspector(new PropertyMapping
                    {
                        Type = new TypeReference(property.PropertyType),
                        Member = property
                    }));
                });

            return conventions.FirstOrDefault() != null;
        }
Exemple #2
0
        private bool HasExplicitTypeConvention(Member property)
        {
            // todo: clean this up!
            //        What it's doing is finding if there are any IUserType conventions
            //        that would be applied to this property, if there are then we should
            //        definitely automap it. The nasty part is that right now we don't have
            //        a model, so we're having to create a fake one so the convention will
            //        apply to it.
            var conventions = conventionFinder
                              .Find <IPropertyConvention>()
                              .Where(c =>
            {
                if (!typeof(IUserTypeConvention).IsAssignableFrom(c.GetType()))
                {
                    return(false);
                }

                var criteria   = new ConcreteAcceptanceCriteria <IPropertyInspector>();
                var acceptance = c as IConventionAcceptance <IPropertyInspector>;

                if (acceptance != null)
                {
                    acceptance.Accept(criteria);
                }

                return(criteria.Matches(new PropertyInspector(new PropertyMapping
                {
                    Type = new TypeReference(property.PropertyType),
                    Member = property
                })));
            });

            return(conventions.FirstOrDefault() != null);
        }
        public void CanPassSubCriteriaToAny()
        {
            var subCriteria1 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria1.Expect(x => x.Name, Is.Set);

            var subCriteria2 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria2.Expect(x => x.Type, Is.Set);

            acceptance.Any(subCriteria1, subCriteria2);

            acceptance
                .Matches(new PropertyInspector(new PropertyMapping { Name = "Property1"}))
                .ShouldBeTrue();
        }
        public void CanPassSubCriteriaToAny()
        {
            var subCriteria1 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria1.Expect(x => x.Name, Is.Set);

            var subCriteria2 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria2.Expect(x => x.Type, Is.Set);

            acceptance.Any(subCriteria1, subCriteria2);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1");
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
Exemple #5
0
        public void CanPassSubCriteriaToEither()
        {
            var subCriteria1 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria1.Expect(x => x.Name, Is.Set);

            var subCriteria2 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria2.Expect(x => x.Type, Is.Set);

            acceptance.Either(subCriteria1, subCriteria2);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1");
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
Exemple #6
0
        public void CanPassSubCriteriaToAny()
        {
            var subCriteria1 = new ConcreteAcceptanceCriteria <IPropertyInspector>();

            subCriteria1.Expect(x => x.Name, Is.Set);

            var subCriteria2 = new ConcreteAcceptanceCriteria <IPropertyInspector>();

            subCriteria2.Expect(x => x.Type, Is.Set);

            acceptance.Any(subCriteria1, subCriteria2);

            acceptance
            .Matches(new PropertyInspector(new PropertyMapping {
                Name = "Property1"
            }))
            .ShouldBeTrue();
        }
Exemple #7
0
        private void Apply <TInspector, TInstance>(IEnumerable conventions, TInstance instance)
            where TInspector : IInspector
            where TInstance : TInspector
        {
            foreach (IConvention <TInspector, TInstance> convention in conventions)
            {
                var criteria   = new ConcreteAcceptanceCriteria <TInspector>();
                var acceptance = convention as IConventionAcceptance <TInspector>;

                if (acceptance != null)
                {
                    acceptance.Accept(criteria);
                }

                if (criteria.Matches(instance))
                {
                    convention.Apply(instance);
                }
            }
        }