Exemple #1
0
 public MapTypeContext(MapContext context, Dictionary <string, List <ColumnInfo> > columnNames, Type targetType, string name, string currentPrefix, Expression getExisting)
 {
     _context      = context;
     _columnNames  = columnNames;
     TargetType    = targetType;
     Name          = name;
     GetExisting   = getExisting;
     CurrentPrefix = currentPrefix ?? "";
 }
Exemple #2
0
        private Func <IDataRecord, T> CreateMapInternal <T>(Action <IMapCompilerSettings> setup)
        {
            var settings        = new CompilationSettings();
            var compilerBuilder = new MapCompilerSettings(settings);

            setup?.Invoke(compilerBuilder);
            var operation = new MapContext(Provider, typeof(T), settings);
            var map       = Context.MapCompiler.Compile <T>(operation, Reader.Reader);

            return(map);
        }
Exemple #3
0
        public Func <IDataRecord, T> Compile <T>(MapContext operation, IDataReader reader)
        {
            Argument.NotNull(operation, nameof(operation));

            // For all other cases, fall back to normal recursive conversion routines.
            var state       = operation.CreateContextFromDataReader(reader);
            var expressions = _compiler.Compile(state);
            var statements  = expressions.Expressions.Concat(new[] { expressions.FinalValue }).Where(e => e != null);

            var lambdaExpression = Expression.Lambda <Func <IDataRecord, T> >(
                Expression.Block(
                    typeof(T),
                    expressions.Variables,
                    statements
                    ),
                operation.RecordParam
                );

            DumpCodeToDebugConsole(lambdaExpression);
            return(lambdaExpression.Compile());
        }