poke icon indicating copy to clipboard operation
poke copied to clipboard

Need implicit conversion for private static method call args

Open vors opened this issue 10 years ago • 0 comments

Add-Type @'
namespace foo5
{
    public class bar
    {
        private static int fooL(System.Reflection.MethodInfo mi) { return 1; }
    }
}
'@

$f = [foo5.bar] | peek
$mi = [System.Collections.ObjectModel.Collection[PSObject]].GetMethods() | ? {$_.Name -eq 'Add'}
$f.fooL($mi)

Expected output:

1

Actual error

Exception calling "fooL" with "1" argument(s): "Exception calling "Invoke" with "5" argument(s): "Object of type 
'System.Management.Automation.PSObject' cannot be converted to type 'System.Reflection.MethodInfo'.""
At line:13 char:1
+ $f.fooL($mi)
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ScriptMethodRuntimeException

Workaround: cast arg explicitly

$f.fooL([System.Reflection.MethodInfo]$mi)

vors avatar Oct 23 '15 02:10 vors