Esempio n. 1
0
 public ToStringExpressionVisitor(ParameterExpression param, CachedEntityExpression root)
 {
     this.root         = root;
     this.replacements = new Dictionary <ParameterExpression, Expression> {
         { param, root }
     };
 }
Esempio n. 2
0
    public static Expression <Func <PrimaryKey, string> > GetToString <T>(CachedTableConstructor constructor, Expression <Func <T, string> > lambda)
    {
        Table table = (Table)constructor.table;

        var param = lambda.Parameters.SingleEx();

        if (param.Type != table.Type)
        {
            throw new InvalidOperationException("incorrect lambda paramer type");
        }

        var pk = Expression.Parameter(typeof(PrimaryKey), "pk");

        var root = new CachedEntityExpression(pk, typeof(T), constructor, null, null);

        var visitor = new ToStringExpressionVisitor(param, root);

        var result = visitor.Visit(lambda.Body);

        return(Expression.Lambda <Func <PrimaryKey, string> >(result, pk));
    }
Esempio n. 3
0
    private Expression BindMember(CachedEntityExpression n, Field field, Expression?prevPrimaryKey)
    {
        Expression body = GetField(field, n.Constructor, prevPrimaryKey);

        ConstantExpression tab = Expression.Constant(n.Constructor.cachedTable, typeof(CachedTable <>).MakeGenericType(((Table)n.Constructor.table).Type));

        Expression origin = Expression.Convert(Expression.Property(Expression.Call(tab, "GetRows", null), "Item", n.PrimaryKey.UnNullify()), n.Constructor.tupleType);

        var result = ExpressionReplacer.Replace(body, new Dictionary <ParameterExpression, Expression> {
            { n.Constructor.origin, origin }
        });

        if (!n.PrimaryKey.Type.IsNullable())
        {
            return(result);
        }

        return(Expression.Condition(
                   Expression.Equal(n.PrimaryKey, Expression.Constant(null, n.PrimaryKey.Type)),
                   Expression.Constant(null, result.Type.Nullify()),
                   result.Nullify()));
    }