Skip to content

Commit

Permalink
feat: Namespace.get/set_Pattern ( Fixes #1137 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jun 29, 2024
1 parent 9813214 commit a63bdf6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Types/Namespace/get_Pattern.ps1
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'
15 changes: 15 additions & 0 deletions Types/Namespace/set_Pattern.ps1
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)

0 comments on commit a63bdf6

Please sign in to comment.