< Summary - Kestrun — Combined Coverage

Information
Class: Private.Variable._NormalizeValueToDictionary
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Variable/_NormalizeValueToDictionary.ps1
Tag: Kestrun/Kestrun@6135d944f8787fb570e4dfbacac6e80312799a86
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 51
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/01/2025 - 20:55:19 Line coverage: 0% (0/18) Total lines: 51 Tag: Kestrun/Kestrun@638a27c2dd54103f693f023b6ba5f56a884caafa

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Variable/_NormalizeValueToDictionary.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Recursively normalizes a value into a form suitable for Dictionary[string, object].
 4.DESCRIPTION
 5    Recursively normalizes a value into a form suitable for Dictionary[string, object].
 6    - Unwraps PSObject shells
 7    - Converts IDictionary to Dictionary[string, object]
 8    - Converts IEnumerable (except string) to List[object]
 9    - Primitives and POCOs are returned as-is
 10.PARAMETER Value
 11    The value to normalize.
 12.PARAMETER Depth
 13    Current recursion depth to prevent infinite loops.
 14.PARAMETER MaxRecursionDepth
 15    Maximum recursion depth. Defaults to 8.
 16.OUTPUTS
 17    The normalized value or $null if the input is $null or could not be normalized.
 18.NOTES
 19    Limits recursion depth to 8 levels.
 20#>
 21function _NormalizeValueToDictionary([object]$Value, [int]$Depth, [int]$MaxRecursionDepth = 8) {
 022    if ($null -eq $Value) { return $null }
 023    if ($Depth -gt $MaxRecursionDepth) { return ($Value.ToString()) }
 24
 25    # Unwrap PSObject shell
 026    if ($Value -is [System.Management.Automation.PSObject]) {
 027        $base = $Value.BaseObject
 028        if ($null -eq $base -or $base -eq $Value) { return $Value.ToString() }
 029        return _NormalizeValueToDictionary $base ($Depth + 1)
 30    }
 31
 32    # Hashtable / IDictionary → new Dictionary[string, object]
 033    if ($Value -is [System.Collections.IDictionary]) {
 034        $out = [System.Collections.Generic.Dictionary[string, object]]::new()
 035        foreach ($key in $Value.Keys) {
 036            if ([string]::IsNullOrWhiteSpace([string]$key)) { continue }
 037            $nv = _NormalizeValue $Value[$key] ($Depth + 1)
 038            if ($null -ne $nv) { $out[[string]$key] = $nv }
 39        }
 040        return $out
 41    }
 42
 43    # Enumerable (but not string) → List<object>
 044    if ($Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])) {
 045        $list = New-Object System.Collections.Generic.List[object]
 046        foreach ($item in $Value) { $list.Add((_NormalizeValueToDictionary $item ($depth + 1))) }
 047        return $list
 48    }
 49
 050    return $Value  # primitive / POCO
 51}

Methods/Properties

_NormalizeValueToDictionary()