/// <summary> /// Adds (or gets) a source <see cref="PropertySrceMapper{TSrce, TSrceProperty, TDest}"/>. /// </summary> /// <typeparam name="TSrceProperty">The source property <see cref="Type"/>.</typeparam> /// <param name="srcePropertyExpression">The <see cref="Expression"/> to reference the source entity property.</param> /// <param name="property">An <see cref="Action"/> enabling access to the created <see cref="PropertyMapper{TSrce, TSrceProperty, TDest, TDestProperty}"/>.</param> /// <returns>The <see cref="EntityMapper{TSrce, TDest}"/>.</returns> public virtual EntityMapper <TSrce, TDest> HasSrceProperty <TSrceProperty>(Expression <Func <TSrce, TSrceProperty> > srcePropertyExpression, Action <PropertySrceMapper <TSrce, TSrceProperty, TDest> > property = null) where TSrceProperty : class { if (srcePropertyExpression == null) { throw new ArgumentNullException(nameof(srcePropertyExpression)); } var spe = PropertyExpression <TSrce, TSrceProperty> .Create(srcePropertyExpression); var px = GetBySrcePropertyName(spe.Name); if (px != null && (px.DestPropertyName != null)) { throw new ArgumentException($"Source property '{srcePropertyExpression.Name}' mapping already exists with a different destination property name"); } PropertySrceMapper <TSrce, TSrceProperty, TDest> p = null; if (px == null) { p = new PropertySrceMapper <TSrce, TSrceProperty, TDest>(spe); AddPropertyMapper(p); } else { p = (PropertySrceMapper <TSrce, TSrceProperty, TDest>)px; } property?.Invoke(p); return(this); }
/// <summary> /// Adds a source <see cref="PropertySrceMapper{TSrce, TSrceProperty, TDest}"/> to the mapper. /// </summary> /// <typeparam name="TSrceProperty">The source property <see cref="Type"/>.</typeparam> /// <param name="srcePropertyExpression">The <see cref="Expression"/> to reference the source entity property.</param> /// <returns>The <see cref="PropertySrceMapper{TSrce, TSrceProperty, TDest}"/>.</returns> public virtual PropertySrceMapper <TSrce, TSrceProperty, TDest> SrceProperty <TSrceProperty>(Expression <Func <TSrce, TSrceProperty> > srcePropertyExpression) where TSrceProperty : class { if (srcePropertyExpression == null) { throw new ArgumentNullException(nameof(srcePropertyExpression)); } PropertySrceMapper <TSrce, TSrceProperty, TDest> mapping = new PropertySrceMapper <TSrce, TSrceProperty, TDest>(srcePropertyExpression); AddPropertyMapper(mapping); return(mapping); }