47 lines
1.4 KiB
PowerShell
47 lines
1.4 KiB
PowerShell
function Resolve-ConfigurationDataReference {
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Path,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[AllowEmptyString()]
|
|
[string]
|
|
$Property = "",
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
$Context
|
|
)
|
|
|
|
$ReferenceKey = $Path
|
|
if(-not [string]::IsNullOrWhiteSpace($Property)){
|
|
$ReferenceKey = "$Path::$Property"
|
|
}
|
|
|
|
if($Context.ReferenceCache.ContainsKey($ReferenceKey)){
|
|
return $Context.ReferenceCache[$ReferenceKey]
|
|
}
|
|
|
|
if($Context.ResolvingReferences.ContainsKey($ReferenceKey)){
|
|
$Stack = @($Context.ResolvingReferences.Keys) + $ReferenceKey
|
|
throw "Circular configuration data reference detected: $($Stack -join ' -> ')."
|
|
}
|
|
|
|
$Context.ResolvingReferences[$ReferenceKey] = $true
|
|
try {
|
|
$RawValue = Get-ConfigurationDataPathValue -Value $Context.ConfigurationData -Path $Path
|
|
$ResolvedValue = Resolve-ConfigurationDataValue -Value $RawValue -Context $Context
|
|
|
|
if(-not [string]::IsNullOrWhiteSpace($Property)){
|
|
$ResolvedValue = Get-ConfigurationDataObjectPropertyValue -Value $ResolvedValue -Property $Property -Path $Path
|
|
}
|
|
|
|
$Context.ReferenceCache[$ReferenceKey] = $ResolvedValue
|
|
return $ResolvedValue
|
|
}
|
|
finally {
|
|
$Context.ResolvingReferences.Remove($ReferenceKey)
|
|
}
|
|
}
|