我注意到大多数Powershell高级函数都声明了映射到特定.Net的标准数据类型(string,int,bool,xml,array,hashtable等)的参数类型。在Powershell高级功能中使用非标准参数数据类型
如何使用另一个.Net数据类型声明高级函数参数?例如,这里是一个人为的例子:
function Do-Something
{
[CmdletBinding()]
Param(
[System.Xml.XPathNodeList] $nodeList
)
Begin {}
Process
{
Foreach ($node in $nodeList)
{
Write-Host $node
}
}
End {}
}
# Prepare to call the function:
$xml = [xml](get-content .\employee.xml)
$nodeList = $xml.SelectNodes("//age")
# Call the function passing an XPathNodeList:
do-something $nodeList
调用此函数导致以下运行时错误:()
Unable to find type [System.Xml.XPathNodeList]: make sure that the assembly
containing this type is loaded.
可以这样用LoadWithPartialName实现的呢?怎么样?
假设这是可能的,这里有一个辅助问题:这种方式使用非标准类型会违背“最佳实践”吗?
哎呦 - 错过了上面列出CmdletBinding,Keith的是完美的。 – 2011-02-22 21:32:19