Exemplo n.º 1
0
        /// <summary>
        /// 查询规则(NoSQL)子集。
        /// </summary>
        /// <param name="list">规则列表</param>
        /// <param name="writer">输出对象</param>
        /// <param name="innerOperation">内联操作符</param>
        protected virtual void QueryChildren(NoSQL.ConditionCollection list, System.IO.TextWriter writer, string innerOperation = " and ")
        {
            bool b = true;

            foreach (NoSQL.Condition item in list)
            {
                if (item.Type == NoSQL.ConditionTypes.Field)
                {
                    if (list.Owner.Type == NoSQL.ConditionTypes.Field)
                    {
                        //throw new System.NotSupportedException("暂不支持 NoSQL.Condition 多级字段:" +list.Owner.Name+"."+ item.Name);
                        continue;
                    }
                    if (item.Children.Count == 1 && item.Children[0].Type == NoSQL.ConditionTypes.Field)
                    {
                        continue;
                    }
                    if (QueryChildrenFieldPre(item, writer, b ? "" : innerOperation, ref b))
                    {
                        continue;
                    }
                    {
                        var children_builder = new StringBuilder();
                        using (var children_writer = new StringWriter(children_builder)) {
                            var old_b = b;
                            QueryChildren(item.Children, children_writer);
                        }
                        if (children_builder.Length == 0)
                        {
                            continue;
                        }
                        if (!b)
                        {
                            writer.Write(innerOperation);
                        }
                        writer.Write(_dialect.PreName(item.GetNames()));
                        writer.Write(children_builder.ToString());
                    }
                }
                else if (item.Type == NoSQL.ConditionTypes.Logical)
                {
                    QueryChildrenLogical(item, writer, b ? "" : innerOperation);
                }
                b = false;
            }
        }
Exemplo n.º 2
0
 void ToObject_Children(System.Collections.Generic.Dictionary <string, object> parent, ConditionCollection list)
 {
     foreach (Condition item in list)
     {
         if (item.Children.Count > 0)
         {
             if (item.Children.IsArray)
             {
                 System.Collections.Generic.List <object> values = new System.Collections.Generic.List <object>();
                 parent.Add(item.Name, values);
                 foreach (Condition p in item.Children)
                 {
                     System.Collections.Generic.Dictionary <string, object> root2 = new System.Collections.Generic.Dictionary <string, object>();
                     root2.Add(p.Name, p.ToObject());
                     values.Add(root2);
                 }
             }
             else
             {
                 System.Collections.Generic.Dictionary <string, object> values = new System.Collections.Generic.Dictionary <string, object>(System.StringComparer.OrdinalIgnoreCase);
                 parent.Add(item.Name, values);
                 ToObject_Children(values, item.Children);
             }
         }
         else
         {
             parent.Add(item.Name, item.Value);
         }
     }
 }