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
StartAutomating authored and StartAutomating committed Jun 29, 2024
1 parent dea31f3 commit 9cd34f2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions PipeScript.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,67 @@ foreach ($psProperty in $theseProperties) {
<Members>
</Members>
</Type>
<Type>
<Name>Namespace</Name>
<Members>
<ScriptProperty>
<Name>Pattern</Name>
<GetScriptBlock>
&lt;#
.SYNOPSIS
Gets the namespace pattern.
.DESCRIPTION
Gets the pattern of a namespace object.
#&gt;
# 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'

</GetScriptBlock>
<SetScriptBlock>
&lt;#
.SYNOPSIS
Sets the namespace pattern.
.DESCRIPTION
Sets the pattern of a namespace object.
#&gt;
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)
</SetScriptBlock>
</ScriptProperty>
</Members>
</Type>
<Type>
<Name>System.Management.Automation.Language.ParamBlockAst</Name>
<Members>
Expand Down

0 comments on commit 9cd34f2

Please sign in to comment.