diff --git a/Types/AST/Alias.psd1 b/Types/AST/Alias.psd1 new file mode 100644 index 000000000..073f4cdd4 --- /dev/null +++ b/Types/AST/Alias.psd1 @@ -0,0 +1,3 @@ +@{ + "GetCollectionAndIndex" = "GetRelativeIndex" +} \ No newline at end of file diff --git a/Types/AST/GetRelativeIndex.ps1 b/Types/AST/GetRelativeIndex.ps1 new file mode 100644 index 000000000..de606d38c --- /dev/null +++ b/Types/AST/GetRelativeIndex.ps1 @@ -0,0 +1,22 @@ + +$thisCollection,$thisIndex = $null,-1 +:FindThisIndex foreach ($parentProperty in $this.Parent.psobject.Properties) { + if ($parentProperty -is [PSScriptProperty] -or $parentProperty -is [PSNoteProperty]) { + continue FindThisIndex + } + $currentProperty = $this.Parent.($parentProperty.Name) + if (-not $currentProperty.IndexOf) { continue } + + + if ($currentProperty.IndexOf($this) -ge 0) { + $thisCollection = $currentProperty + $thisIndex = $thisCollection.IndexOf($this) + break FindThisIndex + } + +} + +return ([PSCustomObject][Ordered]@{ + Collection = $thisCollection + Index = $thisIndex +}) \ No newline at end of file