Skip to content

Instantly share code, notes, and snippets.

@XPlantefeve
Created March 19, 2015 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XPlantefeve/a218753224743803eaf3 to your computer and use it in GitHub Desktop.
Save XPlantefeve/a218753224743803eaf3 to your computer and use it in GitHub Desktop.
Module as object
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