Esempio n. 1
0
        protected virtual LambdaExpression ClassMap()
        {
            DetermineAssignments();

            var input  = CurrentJob.InputParameter;
            var output = CurrentJob.OutputParameter;

            _ = Expression.Label(CurrentJob.Output, "_return");

            var        nullCheck    = Expression.NotEqual(input, Expression.Constant(null, input.Type));
            var        ctorResolver = GetConstructorResolver();
            var        ctor         = CurrentJob.GetConstructor(ctorResolver);
            var        newInstance  = Expression.Assign(output, Expression.Coalesce(output, ctor));
            Expression body;

            if (Tracking.ContainsKey(CurrentJob.Input) && Tracking[CurrentJob.Input])
            {
                body = GetCacheBlock(newInstance, nullCheck);
            }
            else
            {
                body = Expression.Block(
                    Expression.IfThen(nullCheck, Expression.Block(new Expression[] { newInstance }.Concat(CurrentJob.GetAssignments()))),
                    output
                    );
            }

            return(Expression.Lambda(body, input, output, CurrentJob.CacheParameter));
        }