From 03ea687e3e132e82621fa3008089224c218d0dcd Mon Sep 17 00:00:00 2001 From: Iristyle Date: Wed, 13 Mar 2013 10:03:03 -0400 Subject: [PATCH] FIX: Merge-JsonSimpleMap - First time hash is undefined, copying it is not a good approach - instead, create a new empty hash and copy values in --- core/JsonHelpers.ps1 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/core/JsonHelpers.ps1 b/core/JsonHelpers.ps1 index dc46d7f..b697f80 100644 --- a/core/JsonHelpers.ps1 +++ b/core/JsonHelpers.ps1 @@ -120,24 +120,23 @@ function Merge-JsonSimpleMap if (!$Destination.$Name) { $Destination | - Add-Member -Name $Name -Value $SimpleMap -MemberType NoteProperty + Add-Member -Name $Name -Value ([PSCustomObject]@{}) -MemberType NoteProperty } - else - { - $currentHash = $Destination.$Name - $SimpleMap.PSObject.Properties | - % { - if (!$currentHash.($_.Name)) - { - $currentHash | - Add-Member -Name ($_.Name) -Value $_.Value -MemberType NoteProperty - } - else - { - $currentHash.($_.Name) = $_.Value - } + + $currentHash = $Destination.$Name + $SimpleMap.PSObject.Properties | + % { + $key = $_.Name + if (!$currentHash.$key) + { + $currentHash | + Add-Member -Name $key -Value $_.Value -MemberType NoteProperty } - } + else + { + $currentHash.$key = $_.Value + } + } } function Create-CustomObjectKey