![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Dynamically adding properties to an object instance Hi folks, Is there a way to dynamically add properties to an object instance similar to the way PowerShell's XML data type adds properties for elements and attributes (e.g. $xml.RootNode.Customer.Id)? I want to do something similar for DataSet and DataTable objects (e.g. $ds.CustomerTable.Rows[10].FirstNameColumn). On a similar note, is there a way to add a ScriptProperty in my types.ps1xml file (or somewhere else) that serves as a "catch all" (so, if I type $myobj.UnknownProperty, it will run my script and let it return a value for that non-existent property)? Thanks! Dan |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Dynamically adding properties to an object instance add-member cmdlet lets you add properties/scriptblocks/etc to an object instance. ps:> get-help add-member -full for additional info including examples. gaurhoth <dan.farino@gmail.com> wrote in message news:1166566716.960243.125530@n67g2000cwd.googlegroups.com... > Hi folks, > > Is there a way to dynamically add properties to an object instance > similar to the way PowerShell's XML data type adds properties for > elements and attributes (e.g. $xml.RootNode.Customer.Id)? I want to do > something similar for DataSet and DataTable objects (e.g. > $ds.CustomerTable.Rows[10].FirstNameColumn). > > On a similar note, is there a way to add a ScriptProperty in my > types.ps1xml file (or somewhere else) that serves as a "catch all" (so, > if I type $myobj.UnknownProperty, it will run my script and let it > return a value for that non-existent property)? > > Thanks! > Dan > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Inherit from usercontrol - Object not set to instance of an object | .NET General | |||
| datalist -- Object reference not set to an instance of an object. | .NET General | |||
| False IE doc body error - "Object reference not set to an instance of an object" | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||