Esempio n. 1
0
 Refer Parse(NodeValue jsonValue)
 {
     if (jsonValue == null)
     {
         return(new Refer());
     }
     if (jsonValue.Type == NodeValueTypes.Array)
     {
         return(Parse_Array(jsonValue));
     }
     else if (jsonValue.Type == NodeValueTypes.Dictionary)
     {
         Refer refer = new Refer();
         Parse_Dictionary(refer, jsonValue);
         return(refer);
     }
     else if (jsonValue.Type == NodeValueTypes.Object)
     {
         Refer refer = new Refer();
         Parse_Object(refer, jsonValue);
         return(refer);
     }
     else if (jsonValue.Type == NodeValueTypes.String)
     {
         return(Parse_String(jsonValue));
     }
     return(new Refer());
 }
        /// <summary>
        /// 引用关系(NoSQL)。
        /// </summary>
        /// <param name="refer">引用关系。</param>
        /// <param name="selfSource">主查询(表名,$self 为自动识别)</param>
        /// <param name="filter">过滤器。</param>
        /// <returns></returns>
        public virtual ISelectCommandBuilder Refer(NoSQL.Refer refer, string selfSource = "$self", CommandReferFilterDelegate filter = null)
        {
            if (refer == null || (filter != null && !filter(this, refer)))
            {
                return(this);
            }

            if (string.IsNullOrEmpty(selfSource) || string.Equals(selfSource, "$self", System.StringComparison.OrdinalIgnoreCase))
            {
                selfSource = _tableName;
            }

            foreach (NoSQL.ReferEntry item in refer)
            {
                if (item.IsThis)
                {
                    continue;
                }
                _whereBefores.Add(string.Format(" left join {0} as {1} on {1}.{2}={3}.{4}",
                                                _dialect.PreName(PreSelfName(item.Source, selfSource), "."),
                                                _dialect.PreName(item.Name),
                                                _dialect.PreName(item.SourceField),
                                                _dialect.PreName(PreSelfName(item.Target, selfSource)),
                                                _dialect.PreName(item.TargetField, "."))
                                  );
            }
            return(this);
        }
Esempio n. 3
0
            /// <summary>
            /// 解析
            /// </summary>
            /// <param name="value">仅支持string[]、string、{}、object、string(json)</param>
            /// <returns></returns>
            public Refer Parse(object value)
            {
                Refer result = value as Refer;

                if (result != null)
                {
                    return(result);
                }
                return(Parse(NodeValue.As(value)));
            }
Esempio n. 4
0
 void Parse_Object(Refer refer, NodeValue jsonValue)
 {
     string[] pairs = new string[5];
     foreach (System.Reflection.PropertyInfo propertyInfo in jsonValue.ValueType.GetProperties())
     {
         string key = propertyInfo.Name;
         if (string.Equals(key, "by", StringComparison.OrdinalIgnoreCase))
         {
             Parse_Pairs(pairs, 3, new NodeValue(propertyInfo.GetValue(jsonValue.Value, new object[0])));
         }
         else
         {
             pairs[0] = key;
             Parse_Pairs(pairs, 1, new NodeValue(propertyInfo.GetValue(jsonValue.Value, new object[0])));
         }
     }
     refer.Add(Create_Pairs(pairs));
 }
Esempio n. 5
0
            Refer Parse_Array(NodeValue jsonValue)
            {
                Refer result = new Refer();

                foreach (object element in (System.Collections.IEnumerable)jsonValue.Value)
                {
                    NodeValue item = new NodeValue(element);
                    bool      b    = true;
lb_Retury:
                    if (item.Type == NodeValueTypes.Object)
                    {
                        Parse_Object(result, item);
                        continue;
                    }
                    if (item.Type == NodeValueTypes.Dictionary)
                    {
                        Parse_Dictionary(result, item);
                        continue;
                    }
                    if (!b)
                    {
                        continue;
                    }
                    if (item.Type == NodeValueTypes.String)
                    {
                        string text = item.Value as string;
                        if (string.IsNullOrEmpty(text))
                        {
                            continue;
                        }
                        if (text[0] == '[' || text[0] == '{')
                        {
                            item = new NodeValue(JSON.Parse(text));
                            b    = false;
                            goto lb_Retury;
                        }
                        continue;
                    }
                }
                return(result);
            }
Esempio n. 6
0
 void Parse_Dictionary(Refer refer, NodeValue jsonValue)
 {
     string[] pairs = new string[5];
     foreach (object item in (System.Collections.IEnumerable)jsonValue.Value)
     {
         string key = FastWrapper.Get(item, "Key") as string;
         if (string.IsNullOrEmpty(key))
         {
             continue;
         }
         object value = FastWrapper.Get(item, "Value");
         if (string.Equals(key, "by", StringComparison.OrdinalIgnoreCase))
         {
             Parse_Pairs(pairs, 3, new NodeValue(value));
         }
         else
         {
             pairs[0] = key;
             Parse_Pairs(pairs, 1, new NodeValue(value));
         }
     }
     refer.Add(Create_Pairs(pairs));
 }
Esempio n. 7
0
 public ReferInstance()
 {
     _root    = new Refer();
     _asIndex = 1;
 }