Created
March 19, 2015 16:18
-
-
Save XPlantefeve/a218753224743803eaf3 to your computer and use it in GitHub Desktop.
Module as object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-Dog { | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$Name, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('small', 'medium','large', $null)] | |
| [string]$size, | |
| [Parameter(Mandatory=$false)] | |
| [string]$color | |
| ) | |
| $this = New-Module -Argumentlist @($name,$size,$color) -AsCustomObject -ScriptBlock { | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$Name, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('small', 'medium','large', $null)] | |
| [string]$size, | |
| [Parameter(Mandatory=$false)] | |
| [string]$color | |
| ) | |
| function Pee { | |
| "A warm refreshing pee trickles out of {0}" -f $Name | |
| } | |
| Export-ModuleMember -Function Pee -Variable Name, Size, Color | |
| } | |
| $this.PSTypeNames.Insert(0,'dog') | |
| $this | |
| } | |
| $chenil = New-Object System.Collections.ArrayList | |
| [void]$chenil.Add((New-Dog 'Médor')) | |
| [void]$chenil.Add((New-Dog 'Fido')) | |
| [void]$chenil.Add((New-Dog -Name 'Sultan' -size small)) | |
| $chenil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment