C# vs PowerShell

Kyle Hewitt

I'm trying to re-write a C# script in PowerShell. I'm figuring it out piece by piece.

The PowerShell version is telling me 'Cannot find an overload for "Call" and the argument count: "2".'. So I know it's because PS is requiring that the 3rd parameter be present. But, why doesn't the C# require it? Because of the "params"?

What does the params even mean or do in this context? How can I mimic that in PowerShell?

Yes, I left out a lot of code because I didn't feel it pertained to my issue of not understanding what's going on with this particular error.

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)
    }
}
JSteward

In the C# Call parameters is an optional params type.
In your Powershell class, Call has three required parameters, $Parameters is not optional.

It looks like you could omit that parameter in your Powershell script since your not using it but I can't say whether Call2 uses it or not. You may just want to change the signatures of both methods in your Powershell script.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事