private string GenerateBody(RevitFunctionViewModel revitFunction)
        {
            var formulaBody = FunctionTypeAnalizer.GetBlueprint(revitFunction.FunctionType);

            for (int i = 0; i < revitFunction.Arguments.Count; i++)
            {
                string arg = revitFunction.Arguments[i];
                if (arg == "Function")
                {
                    var childFunction = revitFunction.ChildFunctions.First();
                    arg = GenerateBody(childFunction);
                    revitFunction.ChildFunctions.Remove(childFunction);
                }

                if ((revitFunction.FunctionType == RevitEnums.FunctionType.OrFunction ||
                     revitFunction.FunctionType == RevitEnums.FunctionType.AndFunction) &&
                    i > 1)
                {
                    formulaBody = formulaBody.Replace(Convert.ToString(formulaBody.Last()), $",{{{i}}})");
                }
                formulaBody = formulaBody.Replace($"{{{i}}}", arg);
            }

            return(formulaBody);
        }
        private void CheckCommasInFunction(RevitFunctionModel function, string formula, int functionEndPos)
        {
            var numOfArgs = FunctionTypeAnalizer.CheckNumberOfArgs(function.FunctionType);

            if (numOfArgs > 1)
            {
                bool insideChildFunction  = false;
                int  childFunctionCounter = 0;
                var  correctNumOfCommas   = numOfArgs - 1;
                int  numOfCommas          = 0;
                for (int i = function.StartPos + 1; i < functionEndPos; i++)
                {
                    char character = formula[i];
                    if (character.Equals(openingBracket))
                    {
                        if (childFunctionCounter == 0)
                        {
                            insideChildFunction = true;
                        }
                        childFunctionCounter++;
                    }
                    else if (character.Equals(closingBracket))
                    {
                        childFunctionCounter--;
                        if (childFunctionCounter == 0)
                        {
                            insideChildFunction = false;
                        }
                    }

                    if (!insideChildFunction)
                    {
                        if (character.Equals(comma))
                        {
                            numOfCommas++;
                        }
                    }

                    if (correctNumOfCommas < numOfCommas)
                    {
                        throw new Exception($"Unnecessary comma in formula at index {i} - possibly bracket around this index.");
                    }
                }
                if (correctNumOfCommas > numOfCommas)
                {
                    throw new Exception(
                              $"Missing commas in {function.FunctionTypeName}(at index {function.StartPos}).\nFunction should have {correctNumOfCommas} commas but contains only {numOfCommas}.");
                }
            }
        }