My functions looks like following:
function GeneratePermutations() {
Param(
[System.Collections.ArrayList]$Lists,
[ref][System.Collections.ArrayList]$result,
[Int]$depth,
[String]$current
)
if ($depth -eq $Lists.Count)
{
$result.Value.Add($current);
}
else
{
for ($i = 0; $i -lt $Lists[$depth].Count; $i = $i + 1)
{
GeneratePermutations $values $result ($depth + 1) ($current + $Lists[$depth][$i])
# tried as well:
# GeneratePermutations $values [ref]($result.Value) ($depth + 1) ($current + $Lists[$depth][$i])
}
}
}
And I try to use it like following:
$x = New-Object System.Collections.ArrayList
GeneratePermutations $values [ref]($x) 0 ""
I get following exception (in german):
System.Management.Automation.ParameterBindingArgumentTransformationException: Die
Argumenttransformation für den Parameter "result" kann nicht verarbeitet werden. Der Wert "[ref]" vom Typ
"System.String" kann nicht in den Typ "System.Collections.ArrayList" konvertiert werden. --->
System.Management.Automation.ArgumentTransformationMetadataException: Der Wert "[ref]" vom Typ "System.String" kann
nicht in den Typ "System.Collections.ArrayList" konvertiert werden. --->
System.Management.Automation.PSInvalidCastException: Der Wert "[ref]" vom Typ "System.String" kann nicht in den Typ
"System.Collections.ArrayList" konvertiert werden.
bei System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type
resultType)
bei System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType,
Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
bei System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType,
Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
bei System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean
recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)
bei System.Management.Automation.ArgumentTypeConverterAttribute.Transform(EngineIntrinsics engineIntrinsics, Object
inputData, Boolean bindingParameters, Boolean bindingScriptCmdlet)
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Management.Automation.ArgumentTypeConverterAttribute.Transform(EngineIntrinsics engineIntrinsics, Object
inputData, Boolean bindingParameters, Boolean bindingScriptCmdlet)
bei System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter,
CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception
exception)
bei System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
bei System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
bei System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
In Zeile:1 Zeichen:1
+ .\process.ps1
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,process.ps1
I think I have a problem with recursively reusing the result array, can someone tell me how to solve the issue? It seems like powershell wants to convert the result array to string which it apperently can't do, but why does it try to convert it to a string?