示例#1
0
        void IMapBuilder <T> .BuildMaps(IMapContainer <T> map)
        {
            MapBuilderUtility.QualifyName(ref _name, map.Namespace);

            var elementMap = new ElementContainerMap <T>(_name, _required, map.GetType().Name);

            ((IElementMapContainer <T>)map).AddElementMap(_name, elementMap);

            // build children
            builders.ForEach(b => b.BuildMaps(elementMap));
        }
示例#2
0
 void IMapBuilder <TObj> .BuildMaps(IMapContainer <TObj> map)
 {
     if (map is IAttributeMapContainer <TObj> && isAttribute)
     {
         AttributeMap <TObj, TProperty> attributeMap;
         attributeMap = new AttributeMap <TObj, TProperty>(_name, _required, _defaultValue, _writeDefault);
         ((IAttributeMapContainer <TObj>)map).AddAttributeMap(_name, attributeMap);
         attributeMap.Property  = _simpleMemberMap.GetProperty();
         attributeMap.Converter = _simpleMemberMap.GetConverter();
     }
     else if (map is IAttributeMapContainer <TObj> && isAttributeGroup)
     {
         var attributeGroupMap = new AttributeGroupMap <TObj, TProperty>(_name, _groupDefaultValue, _groupHasDefault);
         ((IAttributeMapContainer <TObj>)map).AddAttributeMap(_name, attributeGroupMap);
         attributeGroupMap.Property     = _attributeGroupMap.GetProperty();
         attributeGroupMap.GroupTypeMap = _attributeGroupMap.GetGroupTypeMap();
     }
     else if (map is IElementMapContainer <TObj> && isElement)
     {
         MapBuilderUtility.QualifyName(ref _name, map.Namespace);
         var elementMap = new ElementMap <TObj, TProperty>(_name, _required);
         ((IElementMapContainer <TObj>)map).AddElementMap(_name, elementMap);
         elementMap.Property        = _classMemberMap.GetProperty();
         elementMap.ClassMapFactory = _classMemberMap.GetClassMapFactory();
     }
     else if (map is IElementMapContainer <TObj> && isSimpleElement)
     {
         MapBuilderUtility.QualifyName(ref _name, map.Namespace);
         var simpleElementMap = new SimpleElementMap <TObj, TProperty>(_name, _required);
         ((IElementMapContainer <TObj>)map).AddElementMap(_name, simpleElementMap);
         simpleElementMap.Property        = _simpleMemberMap.GetProperty();
         simpleElementMap.ClassMapFactory = () => new SimpleElementClassMap <TProperty>(_simpleMemberMap.GetConverter());
     }
     else if (map is IElementContentContainer <TObj> && isContent)
     {
         var contentMap = new ContentMap <TObj, TProperty>();
         ((IElementContentContainer <TObj>)map).SetElementContentMap(contentMap);
         contentMap.Property  = _simpleMemberMap.GetProperty();
         contentMap.Converter = _simpleMemberMap.GetConverter();
     }
     else
     {
         var prop = new Property <TObj, TProperty>(_property, null);
         throw new MappingException("Error mapping ({0}).{1}: a property must be mapped to either an attribute, an element, or element conent.", prop.GetTypeName(), prop.GetName());
     }
 }
示例#3
0
        void IMapBuilder <TObj> .BuildMaps(IMapContainer <TObj> map)
        {
            MapBuilderUtility.QualifyName(ref _name, map.Namespace);

            if (isSimple)
            {
                var collectionMap = new SimpleElementCollectionMap <TObj, TProperty>(_name, _required);
                collectionMap.ClassMapFactory = () => new SimpleElementClassMap <TProperty>(_simpleMemberMap.GetConverter());
                collectionMap.Collection      = _simpleMemberMap.GetCollection();
                ((IElementMapContainer <TObj>)map).AddElementMap(_name, collectionMap);
            }
            else if (isClassMap)
            {
                var collectionMap = new ElementCollectionMap <TObj, TProperty>(_name, _required);
                collectionMap.Collection      = _classMemberMap.GetCollection();
                collectionMap.ClassMapFactory = _classMemberMap.GetClassMapFactory();
                ((IElementMapContainer <TObj>)map).AddElementMap(_name, collectionMap);
            }
            else
            {
                var coll = new Collection <TObj, TProperty>(_collection, null);
                throw new MappingException("Error mapping ({0}).{1}: a collection must be mapped to either an an element or simple element.", coll.GetTypeName(), coll.GetName());
            }
        }