-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Namespace.get/set_Pattern ( Fixes #1137 )
- Loading branch information
James Brundage
committed
Jun 29, 2024
1 parent
9813214
commit a63bdf6
Showing
2 changed files
with
48 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,33 @@ | ||
<# | ||
.SYNOPSIS | ||
Gets the namespace pattern. | ||
.DESCRIPTION | ||
Gets the pattern of a namespace object. | ||
#> | ||
# If we already have a cached .Pattern, return it. | ||
if ($this.'.Pattern') { | ||
return $this.'.Pattern' | ||
} | ||
|
||
# Several types of objects can be used directly as patterns. | ||
# These patterns can still be overridden by setting the .Pattern property. | ||
# (in fact, that's also how they are set) | ||
|
||
# If we are actually a regex, set the .Pattern property and return. | ||
if ($this -is [regex]) { | ||
$this.Pattern = "$this" | ||
} | ||
|
||
# If we are a URI, set the .Pattern property to the URI pattern. | ||
if ($this -is [uri]) { | ||
$this.Pattern = [regex]::Escape("$($this.DnsSafeHost)") | ||
} | ||
|
||
if ($this.Name) { | ||
$this.Pattern = "^$([Regex]::Escape($this.Name))" | ||
} | ||
else { | ||
$this.Pattern = [regex]::Escape("$this") | ||
} | ||
|
||
return $this.'.Pattern' |
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 @@ | ||
<# | ||
.SYNOPSIS | ||
Sets the namespace pattern. | ||
.DESCRIPTION | ||
Sets the pattern of a namespace object. | ||
#> | ||
param($value) | ||
|
||
if (-not $Value) { return} | ||
|
||
if ($value -isnot [regex]) { | ||
$value = [regex]::new($value,'IgnoreCase,IgnorePatternWhitespace','00:00:00.01') | ||
} | ||
|
||
$this.psobject.properties.add([psnoteproperty]::new('.Pattern',$value), $true) |