C# 与 PowerShell

C# vs PowerShell

我正在尝试在 PowerShell 中重新编写 C# 脚本。我正在一点一点地弄清楚。

PowerShell 版本告诉我 'Cannot find an overload for "Call" and the argument count: "2".'。所以我知道这是因为 PS 要求存在第三个参数。但是,为什么 C# 不需要它呢?因为 "params"?

在这种情况下,参数甚至意味着什么或做什么? 我如何在 PowerShell 中模仿它?

是的,我遗漏了很多代码,因为我觉得这与我不了解这个特定错误的原因有关。

C#

object dialog = r.Call(ofd, "CreateVistaDialog")

public class Reflector
{
    public object Call(object obj, string func, params object[] parameters)
    {
        return Call2(obj, func, parameters);
    }
}

PowerShell

$Dialog = $Reflector.Call($This.OFD, "CreateVistaDialog")

Class Reflector
{
    [Object]Call([Object]$Obj, [String]$Func, [Object[]]$Parameters)
    {
        return $This.Call2($Obj, $Func, $Parameters)
    }
}

在 C# 中 Call parameters 是一个可选的 params 类型。
在您的 Powershell class 中,Call 具有三个必需参数,$Parameters 不是可选的。

看起来您可以在 Powershell 脚本中省略该参数,因为您没有使用它,但我不能说 Call2 是否使用它。您可能只想在 Powershell 脚本中更改这两种方法的签名。