Skip to content

Instantly share code, notes, and snippets.

@idavis
Created September 20, 2012 19:54
Show Gist options
  • Select an option

  • Save idavis/3757966 to your computer and use it in GitHub Desktop.

Select an option

Save idavis/3757966 to your computer and use it in GitHub Desktop.
Prototypes with Modules
function New-SapiVoice {
return new-prototype "SapiVoice" {
# Define properties
$Speaker = New-Object -ComObject SAPI.SPVoice
$Message = 'Hello, World!'
# Define methods
function Say {
param([string]$Message)
[void]$Speaker.Speak($Message, 1)
}
function SayHello {
Say $Message
}
# Now define what is public
Export-ModuleMember -Function Say,SayHello
}
}
function new-prototype {
param([string]$name, [scriptblock] $initializer)
$prototype = New-Module -AsCustomObject $initializer
$prototype.PSTypeNames.Insert(0,"Prototype#$name")
$prototype
}
$sapiVoice = New-SapiVoice
$sapiVoice.Say('I love PowerShell!')
$sapiVoice.SayHello()
function New-SapiVoice {
return new-prototype "SapiVoice" {
param($first, $second)
Write-Host $first
Write-Host $second
# Define properties
$Speaker = New-Object -ComObject SAPI.SPVoice
$Message = 'Hello, World!'
# Define methods
function Say {
param([string]$Message)
[void]$Speaker.Speak($Message, 1)
}
function SayHello {
Say $Message
}
# Now define what is public
Export-ModuleMember -Function Say,SayHello
} $args
}
function new-prototype {
param([string]$name, [scriptblock] $initializer, $parameters)
$prototype = New-Module -AsCustomObject $initializer -ArgumentList $parameters
$prototype.PSTypeNames.Insert(0,"Prototype#$name")
$prototype
}
$sapiVoice = New-SapiVoice 1 2
$sapiVoice.Say('I love PowerShell!')
$sapiVoice.SayHello()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment