/* Copyright (C) 2008 - 2011 Jordan Marr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ using System; using System.Collections; using System.Reflection; namespace Marr.Data.Mapping.Strategies { /// /// Maps all public properties to DB columns. /// public class PropertyMapStrategy : AttributeMapStrategy { public PropertyMapStrategy(bool publicOnly) : base(publicOnly) { } /// /// Maps properties to DB columns if a ColumnAttribute is not present. /// The entity that is being mapped. /// The current member that is being inspected. /// A ColumnAttribute (is null of one does not exist). /// A list of ColumnMaps. /// protected override void CreateColumnMap(Type entityType, MemberInfo member, ColumnAttribute columnAtt, ColumnMapCollection columnMaps) { if (columnAtt != null) { // Add columns with ColumnAttribute base.CreateColumnMap(entityType, member, columnAtt, columnMaps); } else { if (member.MemberType == MemberTypes.Property) { // Map public property to DB column columnMaps.Add(new ColumnMap(member)); } } } /// /// Maps a relationship if a RelationshipAttribute is present. /// /// The entity that is being mapped. /// The current member that is being inspected. /// A RelationshipAttribute (is null if one does not exist). /// A list of Relationships. protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships) { if (relationshipAtt != null) { // Add relationships by RelationshipAttribute base.CreateRelationship(entityType, member, relationshipAtt, relationships); } else { if (member.MemberType == MemberTypes.Property) { PropertyInfo propertyInfo = member as PropertyInfo; if (typeof(ICollection).IsAssignableFrom(propertyInfo.PropertyType)) { Relationship relationship = new Relationship(member); relationships.Add(relationship); } } } } } }