![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | static methods I have a DLL with two methods one static and one not. public static int Test1(int p) { return 1; } public int Test2(int p) { return 2;} I use the [reflection.assembly] to load it no problem. In script I create an array of strings with the method names and do a New-Object on this class. I want to loop through the array and call the methods on the object with the same parameter. It does not work and I don't know how to call a static method without this syntax[Namespace.Class]::Method |
My System Specs![]() |
| | #2 (permalink) |
| | Re: static methods If you have an instance of your object (let's assume $o) you could call a static method like this: $o.GetType()::Test1(1234) If you have a string for the method name you could build an expression and use invoke-expression: $methodName = "Test1" $arg = 1234 $line = '$o.GetType()::' + $methodName + '($arg)' invoke-expression $line You can get the list of static methods using Get-Member: $o | Get-Member -static -- Nigel Sharples [MSFT] Windows PowerShell Test Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "Doug" <Doug@discussions.microsoft.com> wrote in message news:FE3C6232-FA59-4364-A0F7-7FDA9876F940@microsoft.com... >I have a DLL with two methods one static and one not. > > public static int Test1(int p) { return 1; } > public int Test2(int p) { return 2;} > > I use the [reflection.assembly] to load it no problem. > In script I create an array of strings with the method names and do a > New-Object on this class. > > I want to loop through the array and call the methods on the object with > the > same parameter. > > It does not work and I don't know how to call a static method without this > syntax[Namespace.Class]::Method > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| get help on methods and properties | PowerShell | |||
| Static Events Used By Static Classes | .NET General | |||
| Access a static member on a nested static class. | PowerShell | |||
| Access a static member on a nested static class. | PowerShell | |||
| Output Methods | PowerShell | |||