File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ $method = @{ param([ int32] $t) if ($t -ge 0) { return $this.substring($t)) } else { return $this.substring(($this.Length + $t)) } }
2
+
3
+ $mymethod = @{
4
+ MemberName = 'splice';
5
+ MemberType = 'ScriptMethod';
6
+ # Note the use of param() to define the method parameter and
7
+ # the use of $this to access the instance at hand.
8
+ Value = { param([ int32] $t) if ($t -ge 0) { return $this.substring($t)) } else { return $this.substring(($this.Length + $t)) } }
9
+ Force = $true
10
+ }
11
+
12
+ #
13
+ # The following example defines a new .myLower() method and attaches it to strings
14
+ #
15
+ $mymethod = @{
16
+ MemberName = 'myLower';
17
+ MemberType = 'ScriptMethod';
18
+ # Note the use of param() to define the method parameter and
19
+ # the use of $this to access the instance at hand.
20
+ Value = { param([ int32] $t) $this.toLower() }
21
+ Force = $true
22
+ }
23
+
24
+ Update-TypeData -TypeName 'string' @mymethod
25
+
26
+
27
+
28
+ #
29
+ # Slice() https://github.com/PowerShell/PowerShell/issues/14533
30
+ #
31
+ # String slice()
32
+ $stringMethod = @{
33
+ MemberName = 'slice';
34
+ MemberType = 'ScriptMethod';
35
+ Value = { param([ int32] $t) $( if ($t -ge 0) {$this.substring($t)} else {$this.substring(($this.Length + $t))}) }
36
+ Force = $true
37
+ }
38
+ Update-TypeData -TypeName 'string' @stringMethod
39
+
40
+ # System.Array slice()
41
+ $arrayMethod = @{
42
+ MemberName = 'slice';
43
+ MemberType = 'ScriptMethod';
44
+ Value = { param($t) $this[ $t] }
45
+ Force = $true
46
+ }
47
+ Update-TypeData -TypeName 'System.Array' @arrayMethod
You can’t perform that action at this time.
0 commit comments