private SystemLinq.NewExpression VisitNew(RemoteLinq.NewExpression node)
            {
                if (node.Constructor is null)
                {
                    var type = node.Type.ResolveType(_typeResolver);
                    return(SystemLinq.Expression.New(type));
                }

                var constructor = node.Constructor.ResolveConstructor(_typeResolver)
                                  ?? throw new RemoteLinqException($"Failed to resolve constructor of node {nameof(RemoteLinq.NewExpression)}");

                if (node.Arguments is null)
                {
                    if (node.Members?.Any() ?? false)
                    {
                        var members = node.Members.Select(x => x.ResolveMemberInfo(_typeResolver)).ToArray();
                        return(SystemLinq.Expression.New(constructor, Array.Empty <SystemLinq.Expression>(), members));
                    }
                    else
                    {
                        return(SystemLinq.Expression.New(constructor));
                    }
                }
                else
                {
                    var arguments =
                        from a in node.Arguments
                        select Visit(a);

                    if (node.Members?.Any() ?? false)
                    {
                        var members = node.Members.Select(x => x.ResolveMemberInfo(_typeResolver)).ToArray();
                        return(SystemLinq.Expression.New(constructor, arguments, members));
                    }
                    else
                    {
                        return(SystemLinq.Expression.New(constructor, arguments));
                    }
                }
            }
コード例 #2
0
 public ListInitExpression(NewExpression newExpression, IEnumerable <ElementInit> initializers)
 {
     NewExpression = newExpression.CheckNotNull(nameof(newExpression));
     Initializers  = initializers.CheckNotNull(nameof(initializers)).ToList();
 }
コード例 #3
0
 public ListInitExpression(NewExpression n, IEnumerable <ElementInit> initializers)
 {
     NewExpression = n;
     Initializers  = initializers.ToList();
 }