Skip to content

Commit a63bdf6

Browse files
author
James Brundage
committed
feat: Namespace.get/set_Pattern ( Fixes #1137 )
1 parent 9813214 commit a63bdf6

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Types/Namespace/get_Pattern.ps1

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<#
2+
.SYNOPSIS
3+
Gets the namespace pattern.
4+
.DESCRIPTION
5+
Gets the pattern of a namespace object.
6+
#>
7+
# If we already have a cached .Pattern, return it.
8+
if ($this.'.Pattern') {
9+
return $this.'.Pattern'
10+
}
11+
12+
# Several types of objects can be used directly as patterns.
13+
# These patterns can still be overridden by setting the .Pattern property.
14+
# (in fact, that's also how they are set)
15+
16+
# If we are actually a regex, set the .Pattern property and return.
17+
if ($this -is [regex]) {
18+
$this.Pattern = "$this"
19+
}
20+
21+
# If we are a URI, set the .Pattern property to the URI pattern.
22+
if ($this -is [uri]) {
23+
$this.Pattern = [regex]::Escape("$($this.DnsSafeHost)")
24+
}
25+
26+
if ($this.Name) {
27+
$this.Pattern = "^$([Regex]::Escape($this.Name))"
28+
}
29+
else {
30+
$this.Pattern = [regex]::Escape("$this")
31+
}
32+
33+
return $this.'.Pattern'

Types/Namespace/set_Pattern.ps1

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<#
2+
.SYNOPSIS
3+
Sets the namespace pattern.
4+
.DESCRIPTION
5+
Sets the pattern of a namespace object.
6+
#>
7+
param($value)
8+
9+
if (-not $Value) { return}
10+
11+
if ($value -isnot [regex]) {
12+
$value = [regex]::new($value,'IgnoreCase,IgnorePatternWhitespace','00:00:00.01')
13+
}
14+
15+
$this.psobject.properties.add([psnoteproperty]::new('.Pattern',$value), $true)

0 commit comments

Comments
 (0)