/// <summary> /// Maps to model list. /// </summary> /// <param name="entities">The entities.</param> /// <param name="direction">The direction.</param> /// <returns></returns> public virtual IList <TModel> MapToModelList(ICollection <TEntity> entities, MappingDirections direction) { if (entities == null) { return(null); } return(entities.Select(e => MapToModel(e, direction)).Where(x => x != null).ToList()); }
/// <summary> /// Adds the mappings based on the existing mapping attributes. /// </summary> /// <param name="sourceType">Type of the source.</param> /// <param name="targetType">Type of the target.</param> /// <param name="direction">The mapping direction.</param> /// <returns>An enumeration of property mappings.</returns> private static IEnumerable <ReflectionPropertyMappingInfo <TSource, TTarget> > GetMappings( Type sourceType, Type targetType, MappingDirections direction) { return(from prop in sourceType.GetProperties() from MappingAttribute m in prop.GetCustomAttributes(typeof(MappingAttribute), false) where (m.Direction & direction) == direction where m.OtherType.IsAssignableFrom(targetType) select GetMapping(prop, targetType.GetProperty(m.OtherMemberName), direction)); }
/// <summary> /// Maps to model. /// </summary> /// <param name="entity">The entity.</param> /// <param name="direction">The direction.</param> /// <returns></returns> public virtual TModel MapToModel(TEntity entity, MappingDirections direction) { if (entity == null) { return(null); } var model = new TModel(); ObjectMapper.Map(entity, model); return(model); }
/// <summary> /// Gets the property mapping for two property types. /// </summary> /// <param name="firstProp">The first property.</param> /// <param name="secondProp">The second property.</param> /// <param name="direction">The direction of the mapping.</param> /// <returns>A property mapping object.</returns> private static ReflectionPropertyMappingInfo <TSource, TTarget> GetMapping( PropertyInfo firstProp, PropertyInfo secondProp, MappingDirections direction) { ReflectionPropertyMappingInfo <TSource, TTarget> mappingInfo; if (direction == MappingDirections.From) { mappingInfo = new ReflectionPropertyMappingInfo <TSource, TTarget>( firstProp, secondProp, true); } else { mappingInfo = new ReflectionPropertyMappingInfo <TSource, TTarget>( secondProp, firstProp, true); } return(mappingInfo); }
/// <summary> /// Initializes a new instance of the <see cref="ColumnAttribute"/> class. /// </summary> /// <param name="directions">mapping direction</param> public ColumnAttribute(MappingDirections directions = MappingDirections.Both) { this.directions = directions; }
/// <summary> /// Initializes a new instance of the <see cref="ColumnAttribute"/> class. /// </summary> /// <param name="index">The index of the column.</param> /// <param name="directions">mapping direction</param> public ColumnAttribute(int index, MappingDirections directions = MappingDirections.Both) { this.index = index; this.directions = directions; }
/// <summary> /// Initializes a new instance of the <see cref="ColumnAttribute"/> class. /// </summary> /// <param name="name">The name of the column.</param> /// <param name="directions">mapping direction</param> public ColumnAttribute(string name, MappingDirections directions = MappingDirections.Both) { this.name = name; this.directions = directions; }
/// <summary> /// Initializes a new instance of the <see cref="MappingAttribute" /> class. /// </summary> /// <param name="direction">The mapping direction.</param> /// <param name="otherType">The type of the other class involved in the mapping.</param> /// <param name="otherMemberName">Name of the otherType class's member.</param> public MappingAttribute(MappingDirections direction, Type otherType, string otherMemberName) { Direction = direction; OtherMemberName = otherMemberName; OtherType = otherType; }
/// <summary> /// Initializes a new instance of the <see cref="MappingAttribute"/> class. /// </summary> /// <param name="direction">The mapping direction.</param> /// <param name="otherType">The type of the other class involved in the mapping.</param> /// <param name="otherMemberName">Name of the otherType class's member.</param> public MappingAttribute(MappingDirections direction, Type otherType, string otherMemberName) { this.Direction = direction; this.OtherMemberName = otherMemberName; this.OtherType = otherType; }