如何阻止 PowerShell 解压 Enumerable 对象? [英] How to stop PowerShell from unpacking an Enumerable object?

查看:45
本文介绍了如何阻止 PowerShell 解压 Enumerable 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PowerShell 中处理一个简单的辅助函数,该函数接受几个参数并创建一个自定义 Enumerable 对象并将该对象输出到管道.我遇到的问题是 PowerShell 总是输出一个 System.Array,其中包含由我的自定义 Enumerable 对象枚举的对象.如何防止 PowerShell 解压 Enumerable 对象?

Working on a simple helper function in PowerShell that takes a couple of parameters and creates a custom Enumerable object and outputs that object to the pipeline. The problem I am having is that PowerShell is always outputting a System.Array that contains the objects that are enumerated by my custom Enumerable object. How can I keep PowerShell from unpacking the Enumerable object?

代码:http://gist.github.com/387768

推荐答案

尝试将第 46 行更改为

Try to change the line 46 from

$row

, $row

正如约翰内斯正确指出的那样,一元运算符逗号创建一个包含一个成员的数组.

as Johannes correctly pointed out, the unary operator comma creates an array with one member.

这篇关于如何阻止 PowerShell 解压 Enumerable 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆