Work Items


by dahagi
Mar 12, 2010
1:25 AM

Being evaluated

I've been using your class very frequently and with great success. Well done!
Recently I modified the code slightly to incorporate two small enhancements and I thought that they may be interesting to other people using this code. You can do with it whatever you see fit for - or simply just delete it if you don't like it for any reason. Basically the enhancements are:

- Customized type name ($Object.PSObject.TypeNames[0])
- User can specify which properties should be included in default object view (Properties can be marked with -IncludeInDefaultView)
- For advanced users, the default view can be slightly customized for each property individually (e.g. alignment, columnwidth, label)

Example (using your AnimalTest.ps1) where properties Name and Legs are marked to be shown in default view for objects:

$AnimalClass = New-PSClass Animal {
property Name {
} -set {
Write-Host "Renaming $($this.Class.ClassName) '$($private.Name)' to '$($newName)'"
$private.Name = $newName
} -includeInDefaultView

property Legs {
} -includeInDefaultView

When creating a new object for DogClass you get the following default view:

[DCHWS1] C:\Temp> $DogClass.New("Doggie")

Name Legs
---- ----
Doggie 4

The type name of the dog object is shown here:

[DCHWS1] C:\Temp> $DogClass.New("Doggie") | gm

TypeName: System.Management.Automation.PSCustomObject#Dog

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)

If you have any questions just contact me.



View All
  • 1-1 of 1 Patches
    • Previous
    • 1
    • Next
    • Showing
    • All
    • Patches