- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该参数似乎根本没有被“设置”为参数。验证集不起作用。自动完成也不行。键入参数名称也不起作用。
我知道我以前做过动态参数。但这一次,我错过了一些东西。只是不知道它是什么。
Function Add-Control() {
DynamicParam {
$ParamAttribute = New-Object Parameter
$ParamAttribute.Mandatory = $true
$ParamAttribute.ParameterSetName = '__AllParameterSets'
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$AttributeCollection.Add($ParamAttribute)
$controlTypes = @("TextBox", "Label", "DataGrid")
$AttributeCollection.Add((New-Object ValidateSet($controlTypes)))
$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter('Type', [string], $AttributeCollection)
$RuntimeParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$RuntimeParamDictionary.Add('Type', $RuntimeParam)
return $RuntimeParamDictionary
}
Process {
Write-Host ($PSBoundParameters['Type'])
}
}
Add-Control -Type "Test"
# $null
最佳答案
不确定这是否是一个愚蠢的错误,但我确实有这种感觉。我失踪了
[CmdletBinding()]
Param()
验证集和自动完成现在都可以工作。
希望这对其他人有帮助。
关于powershell - 没有 CmdletBinding() 动态参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49139688/
该参数似乎根本没有被“设置”为参数。验证集不起作用。自动完成也不行。键入参数名称也不起作用。 我知道我以前做过动态参数。但这一次,我错过了一些东西。只是不知道它是什么。 Function Add-Co
根据get-help about_Functions_CmdletBindingAttribute The CmdletBinding attribute is an attribute of fun
我正在编写一个脚本,我想使用 PowerShell 的 CmdletBinding() 。有没有办法在脚本中定义函数?当我尝试时,PowerShell 提示“表达式或语句中出现意外的 token 'f
考虑 PowerShell 代码示例 here : 它在 .ps1 scipt 文件之上有 [CmdletBinding()]。 请注意 [CmdletBinding()] 在文件之上,而不是函数之上
(Powershell 5) 我有以下合并功能: (更新:删除了 process block 中的“优化”continue 调用。) function Find-Defined { begin
我是一名优秀的程序员,十分优秀!