Added helper functions for Arrays and Hashtables

This commit is contained in:
Lord Hepipud 2019-10-05 21:51:39 +02:00
parent 3e98e659bb
commit 298ad37c83
3 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,24 @@
function Add-IcingaHashtableItem()
{
param(
$Hashtable,
$Key,
$Value,
[switch]$Override
);
if ($null -eq $Hashtable) {
return $FALSE;
}
if ($Hashtable.ContainsKey($Key) -eq $FALSE) {
$Hashtable.Add($Key, $Value);
return $TRUE;
} else {
if ($Override) {
$Hashtable[$Key] = $Value;
return $TRUE;
}
}
return $FALSE;
}

View file

@ -0,0 +1,19 @@
function Pop-IcingaArrayListItem()
{
param(
[System.Collections.ArrayList]$Array
);
if ($null -eq $Array) {
return $null;
}
if ($Array.Count -eq 0) {
return $null;
}
$Content = $Array[0];
$Array.RemoveAt(0);
return $Content;
}

View file

@ -0,0 +1,15 @@
function Remove-IcingaHashtableItem()
{
param(
$Hashtable,
$Key
);
if ($null -eq $Hashtable) {
return;
}
if ($Hashtable.ContainsKey($Key)) {
$Hashtable.Remove($Key);
}
}