protected static string GenerateStringFromMultiValue(ParameterMultiValueWrapper parameter, bool isStoredProcedure, ServerType serverType)
        {
            RSTrace.DataExtensionTracer.Assert(parameter != null);
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = parameter.Values.Length;

            for (int i = 0; i < num; i++)
            {
                object        obj            = parameter.Values[i];
                StringBuilder stringBuilder2 = null;
                if (obj == null)
                {
                    throw new InvalidOperationException("Multi value query parameters cannot contain NULL");
                }
                if (obj is byte[])
                {
                    throw new InvalidOperationException("Multi value query parameters cannot contain byte arrays");
                }
                stringBuilder2 = ((obj is byte || obj is sbyte) ? new StringBuilder(((int)obj).ToString(CultureInfo.InvariantCulture)) : ((obj is bool) ? new StringBuilder(((bool)obj) ? "1" : "0") : ((obj is DateTime && serverType == ServerType.Teradata) ? new StringBuilder(((IFormattable)obj).ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture)) : ((!(obj is IFormattable)) ? new StringBuilder(obj.ToString()) : new StringBuilder(((IFormattable)obj).ToString(null, CultureInfo.InvariantCulture))))));
                if (serverType != 0)
                {
                    stringBuilder2.Replace("'", "''");
                    if (!isStoredProcedure)
                    {
                        if (obj is string || obj is char)
                        {
                            if (serverType == ServerType.Teradata)
                            {
                                stringBuilder2.Insert(0, "'");
                            }
                            else
                            {
                                stringBuilder2.Insert(0, "N'");
                            }
                            stringBuilder2.Append("'");
                        }
                        else if (obj is DateTime)
                        {
                            switch (serverType)
                            {
                            case ServerType.SQLServer:
                            case ServerType.SQLServerDataWarehouse:
                                stringBuilder2.Insert(0, "'");
                                stringBuilder2.Append("'");
                                break;

                            case ServerType.Teradata:
                                stringBuilder2.Insert(0, "TIMESTAMP '");
                                stringBuilder2.Append("'");
                                break;

                            default:
                                stringBuilder2.Insert(0, "TO_DATE('");
                                stringBuilder2.Append("','MM/DD/YYYY HH24:MI:SS')");
                                break;
                            }
                        }
                    }
                }
                if (stringBuilder.Length != 0)
                {
                    stringBuilder.Append(',');
                }
                stringBuilder.Append(stringBuilder2.ToString());
            }
            return(stringBuilder.ToString());
        }
        protected internal virtual bool RewriteMultiValueParameters(int sysParameterCount, ServerType serverType)
        {
            if (0 >= sysParameterCount)
            {
                return(false);
            }
            bool result = false;

            System.Data.IDbCommand underlyingCommand = UnderlyingCommand;
            StringBuilder          stringBuilder     = null;
            RegexOptions           options           = RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.Singleline;
            string str  = Regex.Escape("-+()#,:&*/\\^<=>");
            string text = "([" + str + "\\s])";
            bool   flag = System.Data.CommandType.StoredProcedure == underlyingCommand.CommandType;

            if (!flag)
            {
                stringBuilder = new StringBuilder(underlyingCommand.CommandText);
            }
            int num = 0;

            ParameterCollectionWrapper.Enumerator enumerator = m_parameterCollection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                ParameterWrapper           current = enumerator.Current;
                ParameterMultiValueWrapper parameterMultiValueWrapper = current as ParameterMultiValueWrapper;
                if (parameterMultiValueWrapper != null && parameterMultiValueWrapper.Values != null)
                {
                    result = true;
                    string value = GenerateStringFromMultiValue(parameterMultiValueWrapper, flag, serverType);
                    if (flag)
                    {
                        current.Value = value;
                        continue;
                    }
                    string          str2            = "(?<ParameterName>" + Regex.Escape(parameterMultiValueWrapper.ParameterName) + ")";
                    MatchCollection matchCollection = new Regex(text + str2 + text, options).Matches(stringBuilder.ToString());
                    if (matchCollection.Count > 0)
                    {
                        if (StringComparer.InvariantCultureIgnoreCase.Compare(parameterMultiValueWrapper.ParameterName, "?") == 0)
                        {
                            if (num < matchCollection.Count)
                            {
                                string text2 = matchCollection[num].Result("${ParameterName}");
                                if (text2 != null && 1 == text2.Length)
                                {
                                    stringBuilder.Remove(matchCollection[num].Index + 1, text2.Length);
                                    stringBuilder.Insert(matchCollection[num].Index + 1, value);
                                }
                            }
                        }
                        else
                        {
                            for (int num2 = matchCollection.Count - 1; num2 >= 0; num2--)
                            {
                                string text3 = matchCollection[num2].Result("${ParameterName}");
                                if (text3 != null && 1 < text3.Length)
                                {
                                    RSTrace.DataExtensionTracer.Assert(text3.Length == parameterMultiValueWrapper.ParameterName.Length);
                                    stringBuilder.Remove(matchCollection[num2].Index + 1, text3.Length);
                                    stringBuilder.Insert(matchCollection[num2].Index + 1, value);
                                }
                            }
                        }
                    }
                    if (RSTrace.DataExtensionTracer.TraceVerbose)
                    {
                        RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (removed parameter): " + parameterMultiValueWrapper.ParameterName.MarkAsModelInfo());
                    }
                    underlyingCommand.Parameters.Remove(parameterMultiValueWrapper.UnderlyingParameter);
                }
                else if (parameterMultiValueWrapper != null && parameterMultiValueWrapper.Values == null && StringComparer.InvariantCultureIgnoreCase.Compare(parameterMultiValueWrapper.ParameterName, "?") == 0)
                {
                    num++;
                }
            }
            if (!flag)
            {
                if (RSTrace.DataExtensionTracer.TraceVerbose)
                {
                    RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (original query): " + underlyingCommand.CommandText.MarkAsPrivate());
                    RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (rewritten query): " + stringBuilder.ToString().MarkAsPrivate());
                }
                underlyingCommand.CommandText = stringBuilder.ToString();
            }
            return(result);
        }