void GetValues(IBinaryDataListEntry dlEntry, string value, int iterCnt, IIndexIterator idxItr, enRecordsetIndexType indexType, IList <IDebugItemResult> results, string initExpression, string labelText, string fieldName = null)
        {
            string error;
            int    index = idxItr.FetchNextIndex();

            if (string.IsNullOrEmpty(fieldName))
            {
                IList <IBinaryDataListItem> record = dlEntry.FetchRecordAt(index, out error);
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (IBinaryDataListItem recordField in record)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, false, labelText);
                }
            }
            else
            {
                IBinaryDataListItem recordField = dlEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                bool ignoreCompare = false;

                if (recordField == null)
                {
                    if (dlEntry.Columns.Count == 1)
                    {
                        recordField   = dlEntry.TryFetchIndexedRecordsetUpsertPayload(index, out error);
                        ignoreCompare = true;
                    }
                }

                GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, ignoreCompare, labelText);
            }
        }
        static string GetValueForDecisionVariable(Guid dlId, string decisionColumn)
        {
            if (!String.IsNullOrEmpty(decisionColumn))
            {
                IBinaryDataListItem  binaryDataListItem = null;
                ErrorResultTO        errors;
                IBinaryDataListEntry entry = Compiler.Evaluate(dlId, enActionType.User, decisionColumn, false, out errors);
                if (entry != null && entry.IsRecordset)
                {
                    string error;
                    var    indexType = DataListUtil.GetRecordsetIndexType(decisionColumn);
                    if (indexType == enRecordsetIndexType.Numeric)
                    {
                        var index      = int.Parse(DataListUtil.ExtractIndexRegionFromRecordset(decisionColumn));
                        var columnName = DataListUtil.ExtractFieldNameFromValue(decisionColumn);

                        binaryDataListItem = entry.TryFetchRecordsetColumnAtIndex(columnName, index, out error);
                    }
                    else
                    {
                        binaryDataListItem = entry.TryFetchLastIndexedRecordsetUpsertPayload(out error);
                    }
                }
                else
                {
                    if (entry != null)
                    {
                        binaryDataListItem = entry.FetchScalar();
                    }
                }
                if (binaryDataListItem != null)
                {
                    var value = binaryDataListItem.TheValue;
                    // handle \n coming from value ;)
                    value = value.Replace("\r\n", "__R__N__");
                    value = value.Replace("\n", "\r\n");
                    value = value.Replace("__R__N__", "\r\n");
                    return(value);
                }
            }
            return(null);
        }
        /// <summary>
        /// Binds the compiled expression.
        /// </summary>
        /// <returns></returns>
        public IBinaryDataListEntry BindCompiledExpression()
        {
            // very short circuit if no items ;)
            if (_internalKeyMap.Keys.Count == 0)
            {
                CompiledExpression = null;
                return(null);
            }

            // short circuit the long eval for mix mode data ;)
            if (_internalMap.Keys.Count <= 1 && FetchEvaluationIterationCount(Expression) == 1 && CompiledExpression.Length == 3)
            {
                return(_internalKeyMap.Values.FirstOrDefault());
            }

            var replaceValue = string.Empty;

            // Right now we assume there are not ;)
            foreach (var idx in _internalMap.Keys)
            {
                var token    = BuildSubToken(idx);
                var otherKey = _internalMap[idx];
                IBinaryDataListEntry value;
                if (_internalKeyMap.TryGetValue(otherKey, out value))
                {
                    if (value != null)
                    {
                        if (!value.IsRecordset)
                        {
                            var scalar = value.FetchScalar();
                            if (scalar != null)
                            {
                                if (_result == null)
                                {
                                    var toReplace = scalar.TheValue;
                                    CompiledExpression = CompiledExpression.Replace(token, toReplace);
                                }
                                else
                                {
                                    var    itr = _result.FetchRecordsetIndexes();
                                    string replaceVal;
                                    try
                                    {
                                        replaceVal = scalar.TheValue;
                                    }
                                    catch (NullValueInVariableException)
                                    {
                                        replaceVal = null;
                                    }

                                    while (itr.HasMore())
                                    {
                                        var val = itr.FetchNextIndex();

                                        // Fetch the next value from result ;)
                                        try
                                        {
                                            string error;
                                            string template = _result.TryFetchRecordsetColumnAtIndex(GlobalConstants.EvaluationRsField, val, out error).TheValue;
                                            Errors.AddError(error);

                                            template = template.Replace(token, replaceVal);
                                            _result.TryPutRecordItemAtIndex(new BinaryDataListItem(template, _ns, GlobalConstants.EvaluationRsField, val), val, out error);
                                            Errors.AddError(error);
                                        }
                                        catch (NullValueInVariableException)
                                        {
                                            //Do nothing got null
                                        }
                                    }

                                    CompiledExpression = CompiledExpression.Replace(token, replaceVal);
                                }
                            }
                        }
                        else
                        {
                            string error;
                            // build up the complex expression result - this means debug will be out of sync of complex expressions ;)
                            if (_result == null)
                            {
                                IList <Dev2Column> cols = new List <Dev2Column> {
                                    new Dev2Column(GlobalConstants.EvaluationRsField, enDev2ColumnArgumentDirection.Both)
                                };
                                _result = Dev2BinaryDataListFactory.CreateEntry(_ns, string.Empty, cols, BinaryDataList.UID);

                                var max = _internalKeyMap.Values.OrderByDescending(c => c.ItemCollectionSize()).FirstOrDefault();

                                if (max != null)
                                {
                                    var itrToVal = max.ItemCollectionSize();
                                    if (itrToVal == 0)
                                    {
                                        itrToVal = 1;
                                    }

                                    for (int i = 0; i < itrToVal; i++)
                                    {
                                        int idxT = (i + 1);
                                        _result.TryPutRecordItemAtIndex(new BinaryDataListItem(CompiledExpression, _ns, GlobalConstants.EvaluationRsField, idxT), idxT, out error);
                                        Errors.AddError(error);
                                    }
                                }

                                if (IsDebug)
                                {
                                    // attach audit object for debug ;)
                                    _result.ComplexExpressionAuditor = new ComplexExpressionAuditor();
                                }
                            }

                            var idxItr = value.FetchRecordsetIndexes();
                            int expIdx = 1;

                            // we need to treat this as a scalar ;)
                            if (idxItr.Count == 1)
                            {
                                int curVal = idxItr.FetchNextIndex();
                                int amt    = _result.ItemCollectionSize();
                                // ensure we always iterate once ;)
                                if (amt == 0)
                                {
                                    amt = 1;
                                }

                                idxItr = new LoopedIndexIterator(curVal, amt);
                            }

                            // else iterate across the recordset cuz it had a star ;)
                            while (idxItr.HasMore())
                            {
                                try
                                {
                                    var val = idxItr.FetchNextIndex();

                                    // Fetch the next value from result ;)
                                    var template = _result.TryFetchRecordsetColumnAtIndex(GlobalConstants.EvaluationRsField,
                                                                                          expIdx, out error).TheValue;
                                    Errors.AddError(error);

                                    var binaryValue = value.TryFetchIndexedRecordsetUpsertPayload(val, out error);
                                    Errors.AddError(error);

                                    // now bind this result row with the correct data list data ;)
                                    if (binaryValue != null)
                                    {
                                        var preTemplate = template;
                                        var toReplace   = binaryValue.TheValue;
                                        template = template.Replace(token, toReplace);

                                        // In cases when [[[{0}]] is the result, we need to inject the template value
                                        // In cases when [[rec({0}).a]] we need to replace the template pattern ;)
                                        var tmp = CompiledExpression.Replace("[", "").Replace("]", "").Replace(token, string.Empty);
                                        // ReSharper disable ConvertIfStatementToConditionalTernaryExpression
                                        if (tmp.Length > 0)
                                        // ReSharper restore ConvertIfStatementToConditionalTernaryExpression
                                        {
                                            // we have a [[rec({0}.a]] case ;)
                                            replaceValue = toReplace;
                                        }
                                        else
                                        {
                                            replaceValue = template;
                                        }

                                        _result.TryPutRecordItemAtIndex(new BinaryDataListItem(template, _ns, GlobalConstants.EvaluationRsField, expIdx), expIdx, out error);
                                        Errors.AddError(error);

                                        if (IsDebug)
                                        {
                                            var displayValue = DataListUtil.AddBracketsToValueIfNotExist(binaryValue.DisplayValue);
                                            _result.ComplexExpressionAuditor.AddAuditStep(preTemplate, displayValue, token, idx, template, Expression);
                                            _result.ComplexExpressionAuditor.SetMaxIndex(expIdx);
                                        }
                                    }

                                    expIdx++; // inc result index ;)
                                }
                                catch (NullValueInVariableException)
                                {
                                    //Do Nothing got null value
                                }
                            }

                            replaceValue       = DataListUtil.RemoveLanguageBrackets(replaceValue);
                            CompiledExpression = CompiledExpression.Replace(token, replaceValue);
                        }
                    }
                    else
                    {
                        CompiledExpression = CompiledExpression.Replace(token, string.Empty);
                    }
                }
            }

            return(_result);
        }
        void GetValues(IBinaryDataListEntry dlEntry, string value, int iterCnt, IIndexIterator idxItr, enRecordsetIndexType indexType, IList<IDebugItemResult> results, string initExpression, string labelText, string fieldName = null)
        {
            string error;
            int index = idxItr.FetchNextIndex();
            if(string.IsNullOrEmpty(fieldName))
            {
                IList<IBinaryDataListItem> record = dlEntry.FetchRecordAt(index, out error);
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach(IBinaryDataListItem recordField in record)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, false, labelText);
                }
            }
            else
            {
                IBinaryDataListItem recordField = dlEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                bool ignoreCompare = false;

                if(recordField == null)
                {
                    if(dlEntry.Columns.Count == 1)
                    {
                        recordField = dlEntry.TryFetchIndexedRecordsetUpsertPayload(index, out error);
                        ignoreCompare = true;
                    }
                }

                GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, ignoreCompare, labelText);
            }
        }