![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Struct\Class Creation Hi, I have looked in the docs that come with PowerShell and been searching on the web to see if it is possible to define my own struct or class within a script. Have not come across any guidance indicating if this is possible or not, i'm guessing it is not and would like to confirm this. Can work around this but is a bit cumbersome when i have a collection of logical entities that i need to spread across a number of arrays. I guess i expected this as i'm currently inclined to expect that a lot of the functionality from Ruby would be available within PowerShell scripting. Thanks in advance Pat |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Struct\Class Creation "PMcG" <PMcG@discussions.microsoft.com> wrote in message news:8983A578-ABDD-4505-85D9-F4A6B257D966@microsoft.com... > Hi, > I have looked in the docs that come with PowerShell and been searching on > the web to see if it is possible to define my own struct or class within a > script. Have not come across any guidance indicating if this is possible > or > not, i'm guessing it is not and would like to confirm this. Can work > around > this but is a bit cumbersome when i have a collection of logical entities > that i need to spread across a number of arrays. I guess i expected this > as > i'm currently inclined to expect that a lot of the functionality from Ruby > would be available within PowerShell scripting. > In PowerShell you can't create classes or structs in the typical C#/VB sense. However you can use hashtables to create name/value pairs aka a property bag. The nice thing about PowerShell / .NET hashtable is that the value can refer to another hashtable giving you a way to create object hierarchies. However if you need to plug this into another .NET type that is expecting a particular type then you are outta luck unless you want to use Reflection.Emit or LCG (which isn't really using PowerShell anymore) to gen up code for this purpose. -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Struct\Class Creation Keith, I came across an example where you can do something like this $MyObj = new-object System.Object Add-Member -inputobject $MyObj -membertype noteproperty -name Property1 -value 1 Add-Member -inputobject $MyObj -membertype noteproperty -name Property2 -value 1,2,3 Add-Member -inputobject $MyObj -membertype noteproperty -name Property3 -value "......." write-output $MyObj write-output $MyObj.Property1 I havn't spend to much time looking into this but works for me Pat |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| When a class is both an inherited class of another, and alsoimplements an interface method | .NET General | |||
| Q: How are ConfigurationProperty default values assigned toclass/struct attributes? | .NET General | |||
| win32_pingstatus class / dns class | PowerShell | |||
| PDF Creation? | Vista General | |||
| How to map openssl obtained private key parameters to RSAParameters struct members? | .NET General | |||