/* 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.Reflection;
namespace Marr.Data.Mapping.Strategies
{
///
/// Maps fields or properties that are marked with the ColumnAttribute.
///
public class AttributeMapStrategy : ReflectionMapStrategyBase
{
public AttributeMapStrategy()
: base()
{ }
public AttributeMapStrategy(bool publicOnly)
: base(publicOnly)
{ }
public AttributeMapStrategy(BindingFlags flags)
: base(flags)
{ }
///
/// Registers any member with a ColumnAttribute as a ColumnMap.
/// 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)
{
ColumnMap columnMap = new ColumnMap(member, columnAtt);
columnMaps.Add(columnMap);
}
}
///
/// Registers any member with a RelationshipAttribute as a relationship.
///
/// 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)
{
Relationship relationship = new Relationship(member, relationshipAtt);
relationships.Add(relationship);
}
}
}
}