Skip to content

Commit 9cd34f2

Browse files
StartAutomatingStartAutomating
StartAutomating
authored and
StartAutomating
committed
feat: Namespace.get/set_Pattern ( Fixes #1137 )
1 parent dea31f3 commit 9cd34f2

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

PipeScript.types.ps1xml

+61
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,67 @@ foreach ($psProperty in $theseProperties) {
25862586
<Members>
25872587
</Members>
25882588
</Type>
2589+
<Type>
2590+
<Name>Namespace</Name>
2591+
<Members>
2592+
<ScriptProperty>
2593+
<Name>Pattern</Name>
2594+
<GetScriptBlock>
2595+
&lt;#
2596+
.SYNOPSIS
2597+
Gets the namespace pattern.
2598+
.DESCRIPTION
2599+
Gets the pattern of a namespace object.
2600+
#&gt;
2601+
# If we already have a cached .Pattern, return it.
2602+
if ($this.'.Pattern') {
2603+
return $this.'.Pattern'
2604+
}
2605+
2606+
# Several types of objects can be used directly as patterns.
2607+
# These patterns can still be overridden by setting the .Pattern property.
2608+
# (in fact, that's also how they are set)
2609+
2610+
# If we are actually a regex, set the .Pattern property and return.
2611+
if ($this -is [regex]) {
2612+
$this.Pattern = "$this"
2613+
}
2614+
2615+
# If we are a URI, set the .Pattern property to the URI pattern.
2616+
if ($this -is [uri]) {
2617+
$this.Pattern = [regex]::Escape("$($this.DnsSafeHost)")
2618+
}
2619+
2620+
if ($this.Name) {
2621+
$this.Pattern = "^$([Regex]::Escape($this.Name))"
2622+
}
2623+
else {
2624+
$this.Pattern = [regex]::Escape("$this")
2625+
}
2626+
2627+
return $this.'.Pattern'
2628+
2629+
</GetScriptBlock>
2630+
<SetScriptBlock>
2631+
&lt;#
2632+
.SYNOPSIS
2633+
Sets the namespace pattern.
2634+
.DESCRIPTION
2635+
Sets the pattern of a namespace object.
2636+
#&gt;
2637+
param($value)
2638+
2639+
if (-not $Value) { return}
2640+
2641+
if ($value -isnot [regex]) {
2642+
$value = [regex]::new($value,'IgnoreCase,IgnorePatternWhitespace','00:00:00.01')
2643+
}
2644+
2645+
$this.psobject.properties.add([psnoteproperty]::new('.Pattern',$value), $true)
2646+
</SetScriptBlock>
2647+
</ScriptProperty>
2648+
</Members>
2649+
</Type>
25892650
<Type>
25902651
<Name>System.Management.Automation.Language.ParamBlockAst</Name>
25912652
<Members>

0 commit comments

Comments
 (0)