Reputation: 21619
Is it possible to call a .NET method from PowerShell with early binding?
I have a pipeline script which calls a single .NET method in process {...}
. PowerShell calls this method via reflection, and right now Invoke
(not the method itself, just reflection call) takes 70% of total execution time.
The method is always the same, so I would prefer to ask PowerShell not to use reflection at all.
Upvotes: 2
Views: 693
Reputation: 755397
I believe the only types of method call that is early bound in PowerShell, or at least as early bound as is possible in a dynamic language, are the following
I'm not as sure about #2. I believe they still have to use reflection to get at the underlying method.
CmdLets are likely the better choice here. In that case the actual call is bound early, but the parameters still must undergo a conversion process. Try moving your method call into a CmdLet and seeing if that helps you out.
Upvotes: 3