示例#1
0
        public virtual IAttributeBinding <TProp, TAttribute> ToAttribute <TAttribute>(params object[] ctorArguments) where TAttribute : IPropertyAttribute
        {
            TAttribute attribute = (TAttribute)resolver.ResolveInstance <TAttribute>(ctorArguments); //Should we really allow ctor args? This is meant for Domain models that don't have any, but it also removes flexibility to not allow them
            Type       mappingType;
            Type       temp;
            Type       propType = typeof(TProp);

            //REQUIREMENT: Multi value must be either ICollection<T> or T[] where T is the type for the mapping
            if (resolver.ReflectionHelper.IsArray(propType, out temp))
            {
                mappingType = temp;
            }
            else if (resolver.ReflectionHelper.IsGenericCollection(propType, out temp))
            {
                mappingType = temp;
            }
            else
            {
                mappingType = propType;
            }

            ////old: Multi-values must implement ICollection<>, not just IEnumerable<> (this lets us use the Add method)
            //if (typeof(TProp).IsAssignableFrom(typeof(ICollection<>))) //watch out for performance here, do this ONCE
            //    mappingType = typeof(TProp).GetGenericArguments()[0];
            //else
            //    mappingType = typeof(TProp);

            Action <IPropertyAttribute, IBindingContainer> deferredMapping =
                (IPropertyAttribute attr, IBindingContainer container) => attr.ComplexTypeMapping = container.GetMapping(mappingType);
            IPropertyMapping propMapping = new PropertyMapping(propInfo, attribute, deferredMapping);
            var mapping = GetMapping();

            if (mapping != null)
            {
                mapping.Add(propMapping);
            }
            return(new AttributeBinding <TProp, TAttribute>(propMapping, attribute));
        }
        public virtual object BuildMappedModel(IModel modelData, IModelMapping mapping)
        {
            var model = resolver.ResolveInstance(mapping.ModelType);

            return(BuildMappedModel(model, modelData, mapping));
        }