コード例 #1
0
        /// <summary>
        /// 预处理:字段值-字典
        /// </summary>
        /// <param name="builder">构造缓存。</param>
        /// <param name="name">字段名称。</param>
        /// <param name="nodeValue">值包装</param>
        /// <param name="i">顺序。</param>
        /// <returns>返回是否过滤。</returns>
        protected virtual bool PreFieldValue_Dictionary(System.Text.StringBuilder builder, string name, NoSQL.NodeValue nodeValue, ref int i)
        {
            if (nodeValue.Type == NoSQL.NodeValueTypes.Null)
            {
                return(false);
            }
            foreach (object item in (System.Collections.IEnumerable)nodeValue.Value)
            {
                string key = FastWrapper.Get(item, "Key") as string;
                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }
                NoSQL.NodeValue value = new NoSQL.NodeValue(FastWrapper.Get(item, "Value"));
                if (
                    string.Equals(key, "$add", System.StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(key, "$+", System.StringComparison.OrdinalIgnoreCase))
                {
                    i++;
                    if (i > 1)
                    {
                        builder.AppendLine(",");
                    }

                    var p = new CommandParameter()
                    {
                        Name     = Dialect?.ParameterNameGrammar(name),
                        Value    = value.Value,
                        RealType = value.Value?.GetType(),
                    };
                    _fields[name] = p;
                    builder.AppendFormat("    {0}={0}+{1}", _dialect.PreName(name), p.Name);
                    return(true);
                }
                else if (
                    string.Equals(key, "$minus", System.StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(key, "$-", System.StringComparison.OrdinalIgnoreCase))
                {
                    i++;
                    if (i > 1)
                    {
                        builder.AppendLine(",");
                    }
                    var p = new CommandParameter()
                    {
                        Name     = Dialect?.ParameterNameGrammar(name),
                        Value    = value.Value,
                        RealType = value.Value?.GetType(),
                    };
                    _fields[name] = p;
                    builder.AppendFormat("    {0}={0}-{1}", _dialect.PreName(name), p.Name);
                    return(true);
                }
                else if (
                    string.Equals(key, "$now", System.StringComparison.OrdinalIgnoreCase))
                {
                    i++;
                    if (i > 1)
                    {
                        builder.AppendLine(",");
                    }
                    builder.Append("    ").Append(_dialect.PreName(name)).Append('=').Append(_dialect.DateTimeNowGrammar());
                    _fields.Remove(name);
                    return(true);
                }
            }
            return(false);
        }