![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Using dynamic type as function parameter I'm having an issue using a dynamic type as a function parameter in a script file. I dynamically define and create the enum first, and then attempt to define a function with the enum type as a parameter. For example: New-Enum "MyType" Red Blue Green #(from http://blogs.msdn.com/powershell/arc...owershell.aspx ) function MyFunction ([string] $param1, [MyType] $param2) {} If this code is in a script file, I get the error "Unable to find type [MyType]: make sure that the assembly containing this type is loaded." If I define the type at the command line, then execute the script, it's fine. Additionally, I've found if I redefine the function like: function MyFunction ([string] $param1, $param2 = [MyType]::Red) {} I don't get errors when executing the script. However, I lose the strong type of the variable. Any suggestions for how I can keep the custom types on the parameter? |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing dynamic number of parameters to a function as a variable | Robin Moffatt | PowerShell | 10 | 01-30-2008 12:38 AM |
| Function Parameter passing wrong or am I ? | joergH | PowerShell | 4 | 01-23-2007 05:16 PM |
| Return type from function (Is it an egg or a chicken?) | rockmoose | PowerShell | 3 | 12-21-2006 04:41 AM |
| function: Showing valid parameter values for a set | Alex K. Angelopoulos [MVP] | PowerShell | 0 | 07-05-2006 07:50 AM |
| Suggestion: New Parameter Type - PSProviderPath/PSProviderRoot (PsPath/PsRoot) | Alex K. Angelopoulos [MVP] | PowerShell | 4 | 07-02-2006 04:34 PM |