我在网上可以找到的所有关于此操作的信息都是覆盖cmdlet,但是我需要覆盖Windows窗体事件。这是我需要的C#等效项:
protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}
他们说您只是在相同范围内使用该函数的名称,它将自动覆盖它,但这对我不起作用。
如果您指的是方法,克里斯·邓特(Chris Dent)的答案很不错!
对于本机PowerShell cmdlet /功能,我将在以下位置从ServerFault复制我的答案:
是的,您可以Get-ChildItem
在Powershell中覆盖或任何其他cmdlet。
如果在相同范围内使用相同名称创建函数,则将使用您的函数。
例子:
Function Get-ChildItem {
[CmdletBinding()]
param(
# Simulate the parameters here
)
# ... do stuff
}
创建您自己的函数,然后为该函数创建一个别名,该别名与您要覆盖的cmdlet的名称相同。
例子:
Function My-GetChildItem {
[CmdletBinding()]
param(
# Simulate the parameters here
)
# ... do stuff
}
New-Alias -Name 'Get-ChildItem' -Value 'My-GetChildItem' -Scope Global
这种方法很不错,因为在不踩踏内置函数的情况下可以更轻松地测试函数,并且可以控制cmdlet何时被覆盖或不在代码中。
删除别名:
Remove-Item 'Alias:\Get-ChildItem' -Force
about_Command_Precedence列出了解释不同类型的命令的顺序:
如果未指定路径,则Windows PowerShell在运行命令时将使用以下优先级顺序:
- 别名
- 功能
- Cmdlet
- Windows本机命令
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句