コード例 #1
0
        protected string ResolveParamPlaceholders(string input, string prefix, string suffix, ParamSet paramSet, IDbCommand cmd)
        {
            string          output  = string.Empty;
            Regex           reg     = new Regex(@"\$P(\{|\<)[0-9A-Z_a-z]+(\}|\>)");
            MatchCollection matches = reg.Matches(input);
            int             cursor  = 0;

            foreach (Match m in matches)
            {
                string paramName       = m.Value.Substring(3, m.Value.Length - 4); //cutting $P{ and }
                string physicParamName = prefix + paramName + suffix;
                output += input.Substring(cursor, m.Index - cursor);
                output += physicParamName;
                cursor  = m.Index + m.Length;
                IDbDataParameter   param = cmd.CreateParameter();
                ParamSet.ParamInfo pi    = paramSet.GetInfo(paramName);
                param.ParameterName = physicParamName;
                param.DbType        = pi.DbType;
                param.Value         = pi.Value;
                param.Direction     = pi.Direction;
                cmd.Parameters.Add(param);
            }
            if (cursor < input.Length)
            {
                output += input.Substring(cursor);
            }
            return(output);
        }