Example #1
0
    } // End of the GetOtherOptions method

    /// <summary>
    /// This recursive method will get all combinations of a product (variants)
    /// </summary>
    /// <param name="productCombinations">A list that should be filled with product combinations</param>
    /// <param name="lists">A dictionary with product option lists</param>
    /// <param name="depth">The current depth</param>
    /// <param name="current">The current product option array</param>
    public static void GetProductCombinations(List<ProductOption[]> productCombinations, Dictionary<Int32, List<ProductOption>> productOptions, Int32 depth, ProductOption[] current)
    {

        // Loop the dictionary list
        for (int i = 0; i < productOptions[depth].Count; i++)
        {
            // Get the list of product variants
            List<ProductOption> variants = productOptions[depth];

            // Get the current variant
            current[depth] = variants[i];

            // Check if we have reached the end or not
            if (depth < productOptions.Count - 1)
            {
                GetProductCombinations(productCombinations, productOptions, depth + 1, current);
            }
            else
            {
                // Add a copy of the array to the results list
                ProductOption[] resultArray = new ProductOption[current.Length];
                current.CopyTo(resultArray, 0);
                productCombinations.Add(resultArray);
            }
        }

    } // End of the GetProductCombinations method