src/Cassandra/Mapping/MapperFactory.cs
/// <summary>
/// Gets an Expression that represents calling Row.GetValue&lt;T&gt;(columnIndex) and applying any type conversion necessary to
/// convert it to the destination type on the POCO.
/// </summary>
Gets an Expression that represents calling Row.GetValue(columnIndex) and applying any type conversion necessary to
convert it to the destination type on the POCO.
Gets an Expression that represents calling Row . GetValue ( columnIndex ) and applying any type conversion necessary to convert it to the destination type on the POCO .
private Expression GetExpressionToGetColumnValueFromRow(ParameterExpression row, CqlColumn dbColumn, Type pocoDestType)
        {
            ConstantExpression columnIndex = Expression.Constant(dbColumn.Index, IntType);
            MethodCallExpression getValueT = Expression.Call(row, GetValueOfTMethod.MakeGenericMethod(dbColumn.Type), columnIndex);
            if (pocoDestType == dbColumn.Type)
            {
                return getValueT;
            }
            Expression convertedValue;
            Delegate converter = _typeConverter.TryGetFromDbConverter(dbColumn.Type, pocoDestType);
            if (converter == null)
            {
                try
                {
                    convertedValue = Expression.Convert(getValueT, pocoDestType);
                }
                catch (InvalidOperationException ex)
                {
                    var message = String.Format("It is not possible to convert column `{0}` of type {1} to target type {2}", dbColumn.Name, dbColumn.TypeCode, pocoDestType.Name);
                    throw new InvalidTypeException(message, ex);
                }
            }
            else
            {
                convertedValue = Expression.Call(converter.Target == null ? null : Expression.Constant(converter.Target), GetMethod(converter), getValueT);
            }
            Expression defaultValue;
            if (!TryGetCreateEmptyCollectionExpression(dbColumn, pocoDestType, out defaultValue))
            {
                defaultValue = Expression.Default(pocoDestType);
            }
            return Expression.Condition(Expression.Call(row, IsNullMethod, columnIndex), defaultValue, convertedValue);
        }
private Expression GetExpressionToGetColumnValueFromRow ( ParameterExpression row , CqlColumn dbColumn , Type pocoDestType ) { ConstantExpression columnIndex = Expression . Constant ( dbColumn . Index , IntType ) ; MethodCallExpression getValueT = Expression . Call ( row , GetValueOfTMethod . MakeGenericMethod ( dbColumn . Type ) , columnIndex ) ; if ( pocoDestType == dbColumn . Type ) { return getValueT ; } Expression convertedValue ; Delegate converter = _typeConverter . TryGetFromDbConverter ( dbColumn . Type , pocoDestType ) ; if ( converter == null ) { try { convertedValue = Expression . Convert ( getValueT , pocoDestType ) ; } catch ( InvalidOperationException ex ) { var message = String . Format ( " " , dbColumn . Name , dbColumn . TypeCode , pocoDestType . Name ) ; throw new InvalidTypeException ( message , ex ) ; } } else { convertedValue = Expression . Call ( converter . Target == null ? null : Expression . Constant ( converter . Target ) , GetMethod ( converter ) , getValueT ) ; } Expression defaultValue ; if ( ! TryGetCreateEmptyCollectionExpression ( dbColumn , pocoDestType , out defaultValue ) ) { defaultValue = Expression . Default ( pocoDestType ) ; } return Expression . Condition ( Expression . Call ( row , IsNullMethod , columnIndex ) , defaultValue , convertedValue ) ; }
Gets an Expression that represents calling Row.GetValue<T>(columnIndex) and applying any type conversion necessary to
convert it to the destination type on the POCO.
Gets an Expression that represents calling Row . GetValue<T > ( columnIndex ) and applying any type conversion necessary to convert it to the destination type on the POCO .
// Row.GetValue<T>(columnIndex) // No casting/conversion needed since the types match exactly // Check for a converter // No converter is available but the types don't match, so attempt to do: //     (TFieldOrProp) row.GetValue<T>(columnIndex); // Invoke the converter function on getValueT (taking into account whether it's a static method): //     converter(row.GetValue<T>(columnIndex)); // Cassandra will return null for empty collections, so make an effort to populate collection properties on the POCO with // empty collections instead of null in those cases // poco.SomeFieldOrProp = ... createEmptyCollection ...
row
ParameterExpression
dbColumn
CqlColumn
pocoDestType
Type