/// <summary> /// Initializes a new instance of the <see cref="PropertyMapper{TSource, TDestination}"/> class. /// </summary> /// <param name="propertySrc">The property source.</param> /// <param name="propertyDest">The property dest.</param> /// <exception cref="MapperParameterException">Unknown</exception> /// <exception cref="System.MissingMemberException"> /// </exception> /// <exception cref="LambdaSetterException">The setter action for property mapper cannot be null.</exception> public PropertyMapper(string propertySrc, string propertyDest) : base(propertySrc, propertyDest) { PropertyInfo srcProperty; PropertyInfo destProperty; try { srcProperty = typeof(TSource).GetProperty(propertySrc); destProperty = typeof(TSource).GetProperty(propertyDest); } catch (Exception ex) { throw new MapperParameterException("Unknown", string.Format("An error occurs when property source (name: {0}) or property destination (name: {1}) was used", propertySrc, propertyDest), ex); } if (srcProperty == null) { throw new MissingMemberException(typeof(TSource).Name, propertySrc); } if (destProperty == null) { throw new MissingMemberException(typeof(TSource).Name, propertyDest); } Action <TSource, TDestination> action = FactoryMapper.DynamicPropertyMap <TSource, TDestination>(srcProperty, destProperty); if (action == null) { throw new LambdaSetterException("The setter action for property mapper cannot be null."); } this.setter = action; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyMapper{TSource, TDestination}"/> class. /// </summary> /// <param name="srcProperty">The source property.</param> /// <param name="destProperty">The dest property.</param> /// <param name="resolver">The resolver.</param> /// <exception cref="LambdaSetterException">The setter action for property mapper cannot be null.</exception> public PropertyMapper(PropertyInfo srcProperty, PropertyInfo destProperty, ITransformerResolver resolver) : base("[resolver]", destProperty.Name) { Action <TSource, TDestination> action = FactoryMapper.DynamicPropertyMap <TSource, TDestination>(srcProperty, destProperty, resolver); if (action == null) { throw new LambdaSetterException("The setter action for property mapper cannot be null."); } this.setter = action; }