-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* -crlf |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[B|b]in | ||
*.nupkg |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@echo on | ||
|
||
:: Assumes robocopy and nuget.exe both on the path | ||
:: This must be run as the administrator | ||
|
||
SET DIR=%~dp0% | ||
SET DESTDIR=%DIR%bin | ||
|
||
IF EXIST %DESTDIR% goto deletebin | ||
|
||
goto prepare | ||
|
||
:deletebin | ||
rmdir /s /q %DESTDIR% | ||
if %ERRORLEVEL% NEQ 0 goto errors | ||
|
||
:prepare | ||
robocopy %DIR% %DESTDIR%\tools /E /B /NP /R:0 /W:0 /NJH /NJS /NS /NFL /NDL /XF ".git*" "Nuget*" "*.nupkg" /XD "%DIR%nuget" "%DIR%.git" "%DIR%bin" | ||
robocopy %DIR%nuget %DESTDIR% /E /B /NP /R:0 /W:0 /NJH /NJS /NS /NFL /NDL | ||
|
||
:build | ||
nuget pack %DESTDIR%\prototype.nuspec | ||
if %ERRORLEVEL% NEQ 0 goto errors | ||
|
||
goto :eof | ||
|
||
:errors | ||
EXIT /B %ERRORLEVEL% |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function New-SapiVoice { | ||
$prototype = new-prototype @{Message0 = "This is Message 0"} | ||
|
||
$prototype | new-function say { | ||
param([string]$message) | ||
$speaker = new-object -com SAPI.SpVoice | ||
($speaker.Speak($message, 1)) | out-null | ||
} | ||
|
||
$prototype.SayPreRecordedMessage = { . $prototype.say $Message0 } | ||
|
||
# always return the base prototype | ||
$prototype | ||
} | ||
|
||
$voice = New-SapiVoice | ||
$voice.say("Hello, World!") | ||
# says 'Hello, World!' | ||
|
||
# note that because we added the SayPreRecordedMessage directly to the hash base, we have to . invoke it | ||
. $voice.SayPreRecordedMessage | ||
# says 'This is Message 0' | ||
|
||
$voice.SayPreRecordedMessage.Invoke() | ||
# says 'This is Message 0' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function New-SapiVoice { | ||
$prototype = new-prototype @{Message0 = "This is Message 0"} | ||
|
||
#The following would also work and a new, emtpy hash would be the base object | ||
#$prototype = new-prototype $null | ||
#$prototype = new-prototype | ||
|
||
$prototype | new-function say { | ||
param([string]$message) | ||
$speaker = new-object -com SAPI.SpVoice | ||
($speaker.Speak($message, 1)) | out-null | ||
} | ||
|
||
# Add a new key/value pair to this prototype | ||
$prototype.Message1 = "This is Message 1" | ||
|
||
# Add a new property to this prototype | ||
$prototype | new-autoproperty Message2 "This is Message 2" | ||
$prototype | new-property Message3 {"This is Message 3"} | ||
|
||
# Add a proxy property to this prototype | ||
$prototype | new-property Message4 {$this.Message1} {param([String]$value); $this.Message1 = $value} | ||
|
||
# always return the base prototype | ||
$prototype | ||
} | ||
|
||
$voice = New-SapiVoice | ||
$voice.say($voice.Message1) | ||
# says 'This is Message 1' | ||
|
||
$voice.say($voice.Message2) | ||
# says 'This is Message 2' | ||
|
||
$voice.say($voice.Message3) | ||
# says 'This is Message 3' | ||
|
||
$voice.say($voice.Message4) | ||
# says 'This is Message 1' | ||
|
||
$voice.Message4 = "Rewriting Message 1 (via message 4)" | ||
# This doesn't work. A new key, Message4 with the value 'Rewriting Message 1 (via message 4)' is added | ||
# The prototype has a Message4 key and a Message4 value, but the hash access takes precedence | ||
# From now on, all access to Message4 is instead routed to the key Message4 and our proxy is lost. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function New-SapiVoice { | ||
$prototype = new-prototype (new-object psobject) | ||
$prototype | new-function say { | ||
param([string]$message) | ||
$speaker = new-object -com SAPI.SpVoice | ||
($speaker.Speak($message, 1)) | out-null | ||
} | ||
|
||
# Add a new property to this prototype | ||
$prototype | new-autoproperty Message1 "This is Message 1" | ||
$prototype | new-property Message2 {"This is Message 2"} | ||
|
||
# Add a proxy property to this prototype | ||
$prototype | new-property Message3 {$this.Message1} {param([String]$value); $this.Message1 = $value} | ||
|
||
# always return the base prototype | ||
$prototype | ||
} | ||
|
||
$voice = New-SapiVoice | ||
$voice.say($voice.Message1) | ||
# says 'This is Message 1' | ||
|
||
$voice.say($voice.Message2) | ||
# says 'This is Message 2' | ||
|
||
$voice.say($voice.Message3) | ||
# says 'This is Message 1' | ||
|
||
$voice.Message3 = "Rewriting Message 1 (via message 3)" | ||
|
||
$voice.say($voice.Message1) | ||
# says 'Rewriting Message 1 (via message 3)' | ||
|
||
$voice.say($voice.Message3) | ||
# 'says 'Rewriting Message 1 (via message 3)' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
.PARAMETER name | ||
.PARAMETER value | ||
.EXAMPLE | ||
.NOTES | ||
#> | ||
filter New-AutoProperty { | ||
param( | ||
[string]$name, | ||
[object]$value | ||
) | ||
$variable = new-object System.Management.Automation.PSVariable $name, $value | ||
$property = new-object System.Management.Automation.PSVariableProperty $variable | ||
$_.psobject.properties.add($property) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
.PARAMETER name | ||
.PARAMETER value | ||
.EXAMPLE | ||
.NOTES | ||
#> | ||
filter New-Function { | ||
param( | ||
[string]$name, | ||
[scriptblock]$value | ||
) | ||
$method = new-object System.Management.Automation.PSScriptMethod "$name", $value | ||
$_.psobject.members.add($method) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
.PARAMETER name | ||
.PARAMETER value | ||
.EXAMPLE | ||
.NOTES | ||
#> | ||
filter New-Property { | ||
param( | ||
[string]$name, | ||
[scriptblock]$getter, | ||
[scriptblock]$setter = $null | ||
) | ||
$property = new-object System.Management.Automation.PSScriptProperty "$name", $getter, $setter | ||
$_.psobject.properties.add($property) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<# | ||
.SYNOPSIS | ||
Creates a new prototypal object to be used as a base object. | ||
.DESCRIPTION | ||
.PARAMETER baseObject | ||
The object which will be used as the underlying prototype. This is an optional parameter; if it is not included, the base object will be set to an empty hash table. | ||
.EXAMPLE | ||
function new-sapivoice { | ||
$prototype = new-prototype (new-object psobject) | ||
$prototype | new-function say { | ||
param([string]$message) | ||
$speaker = new-object -com SAPI.SpVoice | ||
($speaker.Speak($message, 1)) | out-null | ||
} | ||
} | ||
.NOTES | ||
Changing your base object may cause very different behavior. For example: | ||
function New-HashBasedObject { | ||
$prototype = new-prototype @{Message0 = "This is Message 0"} | ||
$prototype | new-function say { | ||
param([string]$message) | ||
$speaker = new-object -com SAPI.SpVoice | ||
($speaker.Speak($message, 1)) | out-null | ||
} | ||
$prototype | new-autoproperty Message1 "This is Message 1" | ||
# We can reference and rewrite Message1 using Message2 as a proxy | ||
# unless the base is a hash in which setting the value of an existing property | ||
# will instead add a new hash key/value. If your base is a hash, | ||
# and you set Message2, Message1 will remain unchanged, and you will have a new | ||
# hash key Message2 with the value you set. This will also override access to Message2 | ||
# by prefering the key to the property. | ||
$prototype | new-property Message2 {$this.Message1} {param([String]$value); $this.Message1 = $value} | ||
$prototype | ||
} | ||
#> | ||
|
||
function New-Prototype { | ||
param($baseObject = $null) | ||
$base = $baseObject | ||
if($baseObject -eq $null){ $base = @{} } | ||
$prototype = new-object psobject $base | ||
$prototype | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>prototype.ps</id> | ||
<version>0.1.0</version> | ||
<authors>idavis</authors> | ||
<owners>Ian Davis</owners> | ||
<projectUrl>https://github.com/idavis/prototype.ps</projectUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<summary>prototype is a base for creating functions that behave like object prototypes</summary> | ||
<description>prototype is a base for creating functions that behave like object prototypes</description> | ||
<language>en-US</language> | ||
<tags>powershell</tags> | ||
</metadata> | ||
</package> |
Binary file not shown.