Created
September 20, 2012 19:54
-
-
Save idavis/3757966 to your computer and use it in GitHub Desktop.
Prototypes with Modules
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-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() |
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-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