Last active
October 8, 2015 14:10
-
-
Save dfinke/a2c207257a00081dc0b8 to your computer and use it in GitHub Desktop.
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
| ## | |
| ## Thanks to Jum Truher on the PowerShell team https://jtruher3.wordpress.com/ | |
| ## | |
| Update-TypeData -Force -TypeName System.Collections.ArrayList -MemberType ScriptMethod -MemberName Push -Value { | |
| foreach($v in $args) { | |
| [void]$this.Add($v) | |
| } | |
| } | |
| Update-TypeData -Force -Typename System.Collections.ArrayList -MemberType ScriptMethod -MemberName Pop -Value { | |
| if ( $this.count -gt 0 ) { | |
| $val = $this[$this.count-1] | |
| $this.RemoveAt(($this.count - 1)) | |
| return $val | |
| } | |
| } | |
| Update-TypeData -Force -Typename System.Collections.ArrayList -MemberType ScriptMethod -MemberName Shift -Value { | |
| $targetIndex = 1 | |
| if($args.Count -gt 0) { $targetIndex = $args[0] } | |
| $targetIndex-- | |
| if ($this.count -gt 0) { | |
| return 0..$targetIndex | | |
| ForEach { | |
| $this[0] | |
| $this.RemoveAt(0) | |
| } | |
| } | |
| } | |
| Update-TypeData -Force -Typename System.Collections.ArrayList -MemberType ScriptMethod -MemberName Unshift -Value { | |
| for($i = $args.count -1; $i -ge 0; $i--) { | |
| $this.insert(0,$args[$i]) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment