相关疑难解决方法(0)

powershell在什么条件下展开管道中的项目?

考虑以下:

function OutputArray{
    $l = @(,(10,20))
    $l
}

(OutputArray) -is [collections.ienumerable]
# C:\ PS> True
(OutputArray).Count
# C:\ PS> 2
Run Code Online (Sandbox Code Playgroud)

$l 当它进入管道时被"展开". 这个答案表明powershell展开了所有集合. 哈希表是一个集合.但是,哈希表当然不受管道的影响:

function OutputHashtable{
    $h = @{nested=@{prop1=10;prop2=20}}
    $h
}

(OutputHashtable) -is [collections.ienumerable]
# C:\ PS> True
(OutputHashtable).Count
# C:\ PS> 1
Run Code Online (Sandbox Code Playgroud)

这条评论表明,所有IEnumerable都转换为对象数组.但是,数组和散列表都是不可数的:

@(,(10,20)) -is [collections.ienumerable]
#True
@{nested=@{prop1=10;prop2=20}} -is [collections.ienumerable]
#True
Run Code Online (Sandbox Code Playgroud)

究竟,PowerShell将对象"展开"到管道中的条件是什么?

collections powershell ienumerable pipeline

13
推荐指数
1
解决办法
1638
查看次数

标签 统计

collections ×1

ienumerable ×1

pipeline ×1

powershell ×1