Ejemplo n.º 1
0
        internal string Push(object obj, string nameSrc, MetaId metadataToken, IDbParam param)
        {
            if (string.IsNullOrEmpty(nameSrc))
            {
                nameSrc = "p_" + _count++;
            }
            else
            {
                nameSrc = nameSrc.Replace(".", "_");
            }

            var name = _prefix + nameSrc;

            DecodingParameterInfo val;

            if (_parameters.TryGetValue(name, out val))
            {
                //find same metatoken object.
                if (metadataToken != null && metadataToken == val.MetadataToken && Equals(param?.Value, val.Detail?.Value))
                {
                    return(name);
                }

                //make unique name.
                name = MakeUniqueName(nameSrc);
            }

            //register.
            if (param == null)
            {
                param = new DbParamValueOnly()
                {
                    Value = obj
                }
            }
            ;
            _parameters.Add(name, new DecodingParameterInfo()
            {
                MetadataToken = metadataToken, Detail = param
            });

            return(name);
        }

        string MakeUniqueName(string nameSrc)
        {
            while (true)
            {
                var nameCheck = _prefix + nameSrc;
                DecodingParameterInfo val;
                if (!_parameters.TryGetValue(nameCheck, out val))
                {
                    return(nameCheck);
                }
                nameSrc += "_";
            }
        }
    }
Ejemplo n.º 2
0
        internal string Push(object obj, string nameSrc = null, MetaId metadataToken = null, IDbParam param = null)
        {
            if (string.IsNullOrEmpty(nameSrc)) nameSrc = "p_" + _count++;
            else nameSrc = nameSrc.Replace(".", "_");

            var name = _prefix + nameSrc;

            DecodingParameterInfo val;
            if (_parameters.TryGetValue(name, out val))
            {
                //find same metatoken object.
                if (metadataToken != null && metadataToken == val.MetadataToken) return name;

                //make unique name.
                name = MakeUniqueName(nameSrc);
            }

            //register.
            if (param == null) param = new DbParamValueOnly() { Value = obj };
            _parameters.Add(name, new DecodingParameterInfo() { MetadataToken = metadataToken, Detail = param });

            return name;
        }