示例#1
0
        static bool TryAddPropertyFromElement(ITypeMapping typeMapping, ICollection <XElement> elementList, PropertyInfo property, IPropertyStrategy propertyStrategy, string name)
        {
            var element = TakeElement(elementList, name);

            if (element == null)
            {
                return(false);
            }

            var mapper          = propertyStrategy.Mapper ?? MapperSelector.GetFor(property.PropertyType);
            var propertyMapping = new MappingFromElement(element, property, mapper);

            typeMapping.Include(propertyMapping);
            return(true);
        }
示例#2
0
        static bool TryAddPropertyFromAttribute(Type type, ITypeMapping typeMapping, ICollection <XAttribute> attributeList, PropertyInfo property, IPropertyStrategy propertyStrategy, string name)
        {
            var attribute = TakeAttribute(attributeList, name);

            if (attribute == null)
            {
                return(false);
            }

            if (propertyStrategy.Mapper != null)
            {
                throw new AutoConfigMappingException(
                          string.Format(
                              "Custom IMapper '{0}' was configured for mapping property '{1}' of '{2}'. A custom IMapper cannot be specified when mapping from an attribute.",
                              propertyStrategy.Mapper, property.Name, type));
            }

            var propertyMapping = new MappingFromAttribute(attribute, property);

            typeMapping.Include(propertyMapping);

            return(true);
        }