private Expression ConvertExpression(Type typeToConvertTo, Expression recordColumnAccessor,
                                      MappableAttribute mappableAttribute)
 {
     return(mappableAttribute.UseCustomConvertor
         ? BuildCustomConvertorExpression(recordColumnAccessor, typeToConvertTo)
         : Expression.Convert(recordColumnAccessor, typeToConvertTo));
 }
 private static IndexExpression ReaderColumnAccessor(Expression dataReaderParameter,
                                                     PropertyInfo indexerProperty,
                                                     MappableAttribute mappableAttribute)
 {
     return(Expression.MakeIndex(dataReaderParameter, indexerProperty,
                                 new[] { Expression.Constant(mappableAttribute.ReaderColumnName) }));
 }
        private static MethodCallExpression GetOrdinalExpression(Expression dataReaderParameter,
                                                                 MappableAttribute mappableAttribute)
        {
            var getOrdinalMethod = typeof(IDataRecord).GetMethod("GetOrdinal");

            return(Expression.Call(dataReaderParameter, getOrdinalMethod,
                                   Expression.Constant(mappableAttribute.ReaderColumnName)));
        }
        private static ConditionalExpression NullableConvertExpression(Expression dataReaderParameter,
                                                                       MappableAttribute mappableAttribute, PropertyInfo property, Expression convertExpression)
        {
            var getOrdinalExpression              = GetOrdinalExpression(dataReaderParameter, mappableAttribute);
            var isDbNullMethodExpression          = IsDbNullExpression(dataReaderParameter, getOrdinalExpression);
            var ifNullThenNullElseValueExpression = Expression.Condition(isDbNullMethodExpression,
                                                                         Expression.Constant(null, property.PropertyType), convertExpression);

            return(ifNullThenNullElseValueExpression);
        }