private static Func <T> CreateActivatorDelegate() { var constructor = typeof(T).GetConstructor(Type.EmptyTypes); // No parameterless constructor found. if (constructor == null) { return(() => { throw MappingException.NoParameterlessConstructor(typeof(T)); }); } return(Expression.Lambda <Func <T> >(Expression.New(constructor)).Compile()); }
public T Map(IDataRecord record, IEnumerable <string> columns) { var instance = _factory(); foreach (var column in columns) { if (_properties.TryGetValue(column, out var property)) { try { property.SetValue(instance, record[column]); } catch (InvalidCastException e) { throw MappingException.InvalidCast(column, e); } } } return(instance); }