コード例 #1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Method.DeclaringType == typeof(DbFragmentExtensions))
            {
                if (node.Method.Name == nameof(DbFragmentExtensions.Value))
                {
                    return(ToObject(node, node.Method.GetGenericArguments()[0]));
                }
                else if (node.Method.Name == nameof(DbFragmentExtensions.NullValue))
                {
                    return(ToObject(node, typeof(Nullable <>).MakeGenericType(node.Method.GetGenericArguments()[0])));
                }
                else if (node.Method.Name == nameof(DbFragmentExtensions.Server))
                {
                    var dbFragment = FindDbFragment(node.Arguments[0].Type);

                    if (dbFragment != null)
                    {
                        var dbFragmentValue = Expression.Lambda <Func <IDbFragment> >(node.Arguments[0]).Compile().Invoke();
                        var fieldName       = builder.NextFieldName();

                        columns.Add(fieldName, dbFragmentValue);
                    }
                }
            }

            return(base.VisitMethodCall(node));
        }