![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | 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 |
| | #2 (permalink) |
| Guest | 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 |
| | #3 (permalink) |
| Guest | 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 |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Font Creation | Bill | Vista General | 1 | 07-23-2008 04:46 PM |
| PDF Creation? | niagara94 | Vista General | 5 | 05-28-2008 10:54 AM |
| How to map openssl obtained private key parameters to RSAParameters struct members? | SammyBar | .NET General | 1 | 05-23-2008 07:51 AM |
| XML Document creation | ebgreen | PowerShell | 3 | 11-05-2007 06:19 PM |
| help with folder creation | stiggy | Vista General | 1 | 09-16-2007 08:58 AM |