< Summary - Kestrun — Combined Coverage

Information
Class: Private.Yaml.Convert-PSObjectToGenericObject
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Yaml/Convert-PSObjectToGenericObject.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 40
Line coverage: 100%
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 10/13/2025 - 16:52:37 Line coverage: 100% (9/9) Total lines: 40 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Yaml/Convert-PSObjectToGenericObject.ps1

#LineLine coverage
 1# Portions derived from PowerShell-Yaml (https://github.com/cloudbase/powershell-yaml)
 2# Copyright (c) 2016–2024 Cloudbase Solutions Srl
 3# Licensed under the Apache License, Version 2.0 (Apache-2.0).
 4# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 5# Modifications Copyright (c) 2025 Kestrun Contributors
 6
 7<#
 8.SYNOPSIS
 9    Convert a PSObject to a generic object, converting any nested hashtables or lists as well.
 10.DESCRIPTION
 11    This function takes a PSObject as input and converts it to a generic object. It ensures that any nested hashtables o
 12.PARAMETER InputObject
 13    The PSObject to convert.
 14.EXAMPLE
 15    $psObj = [PSCustomObject]@{ Key1 = "Value1"; Key2 = @( "Val2a", "Val2b" ); Key3 = @{ SubKey = "SubVal" } }
 16    $genericObj = Convert-PSObjectToGenericObject -Data $psObj
 17    # $genericObj is now a generic object with the same properties, where Key2 is a List[object] and Key3 is an OrderedD
 18.NOTES
 19    This function is designed to work with PowerShell 7.0 and above.
 20#>
 21function Convert-PSObjectToGenericObject {
 22    param(
 23        [Parameter(Mandatory = $false)]
 24        [System.Object]$InputObject
 25    )
 26
 127    if ($null -eq $InputObject) {
 128        return $InputObject
 29    }
 30
 31    # Use PowerShell's -is operator for efficient type checking
 132    if ($InputObject -is [System.Collections.Specialized.OrderedDictionary]) {
 133        return Convert-OrderedHashtableToDictionary $InputObject
 134    } elseif ($InputObject -is [System.Collections.IDictionary]) {
 135        return Convert-HashtableToDictionary $InputObject
 136    } elseif ($InputObject -is [System.Collections.IList]) {
 137        return Convert-ListToGenericList $InputObject
 38    }
 139    return $InputObject
 40}