/// <summary>
 /// 生成where语句之前的命令。
 /// </summary>
 /// <param name="befores">命令列表。</param>
 /// <returns></returns>
 public virtual ISelectCommandBuilder WhereBefore(params string[] befores)
 {
     if (befores != null && befores.Length > 0)
     {
         foreach (string p in befores)
         {
             if (string.IsNullOrEmpty(p))
             {
                 continue;
             }
             string p10 = StringExtensions.Replace(p, "$self", _dialect.PreName(_tableName), true);
             _whereBefores.Add(p10);
         }
     }
     return(this);
 }
Esempio n. 2
0
        /// <summary>
        /// 将可遍历枚举转换为HashSet&lt;T&gt;对象。
        /// </summary>
        /// <typeparam name="T">任意类型。</typeparam>
        /// <param name="source">可遍历枚举。</param>
        /// <param name="predicate">筛选规则。</param>
        /// <returns>返回一个HashSet&lt;T&gt;对象。</returns>
        public static Symbol.Collections.Generic.HashSet <T> ToHashSet <T>(
#if !net20
            this
#endif
            IEnumerable <T> source, Predicate <T> predicate)
        {
            Symbol.CommonException.CheckArgumentNull(source, "source");

            Symbol.Collections.Generic.HashSet <T> result = new Symbol.Collections.Generic.HashSet <T>();
            foreach (T item in source)
            {
                if (predicate == null || predicate(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 字段值包装处理。
        /// </summary>
        /// <param name="propertyDescriptor">反射对象。</param>
        /// <param name="value">值。</param>
        /// <returns></returns>
        protected virtual object FieldValueWrapper(System.ComponentModel.PropertyDescriptor propertyDescriptor, object value)
        {
            CommandParameter result = new CommandParameter()
            {
                Name     = Dialect?.ParameterNameGrammar(propertyDescriptor.Name),
                RealType = TypeExtensions.GetNullableType(propertyDescriptor.PropertyType),
                Value    = value,
            };

            System.Type type = propertyDescriptor.ComponentType;
            if (!TypeExtensions.IsAnonymousType(type) && (propertyDescriptor.IsReadOnly || propertyDescriptor.ComponentType.GetProperty(propertyDescriptor.Name).GetSetMethod() == null))
            {
                _removedFields.Add(propertyDescriptor.Name);
            }
            //else if (TypeExtensions.IsInheritFrom(propertyDescriptor.ComponentType, typeof(IExtensibleModel)) && propertyDescriptor.Name == "Extendeds")
            //    _removedFields.Add(propertyDescriptor.Name);

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 解析key/value。
        /// </summary>
        /// <param name="values">包含key/value的文本</param>
        /// <param name="needDecode">是否需要解码</param>
        /// <param name="separator">分割符</param>
        public void ParseValues(string values, bool needDecode, params string[] separator)
        {
            if (separator == null || separator.Length == 0)
            {
                CommonException.ThrowArgumentNull("separator");
            }

            if (string.IsNullOrEmpty(values))
            {
                return;
            }
            if (values.StartsWith("?"))
            {
                values = values.Substring(1);
            }
            var keys = new Symbol.Collections.Generic.HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (string item in values.Split(separator, StringSplitOptions.None))
            {
                string key   = string.Empty;
                string value = string.Empty;
                if (item.IndexOf('=') == -1)
                {
                    value = item;
                }
                else
                {
                    string[] array = item.Split('=');
                    key   = array[0];
                    value = array[1];
                }
                if (keys.Add(key))
                {
                    this.Remove(key);
                }
                Add(key, needDecode ? HttpUtility.UrlDecode(value, Encoding) : value);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 注册函数
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool RegisterFunction(System.Type type)
        {
            if (type == null)
            {
                return(false);
            }
            if (!type.IsClass || type.IsAbstract || !type.IsPublic)
            {
                return(false);
            }
            if (type.Assembly.GetName().Name == "System.Data.SQLite")
            {
                if (!LoadAssembly(type.Assembly))
                {
                    return(false);
                }
                GetType("System.Data.SQLite.SQLiteFunction").MethodInvoke("RegisterFunction", type);
                return(true);
            }
            FastWrapper wrapper = GetType("System.Data.SQLite.SQLiteFunction");

            if (!TypeExtensions.IsInheritFrom(type, typeof(SQLiteFunction)))
            {
                return(false);
            }
            if (!_typeNames.Add(type.FullName))
            {
                return(true);
            }
            System.Type newType = GenerateFunctionType(type);
            if (newType == null)
            {
                return(false);
            }
            wrapper.MethodInvoke("RegisterFunction", newType);
            return(true);
        }
        /// <summary>
        /// 生成select 语句。
        /// </summary>
        /// <param name="fields">字段列表。</param>
        /// <returns></returns>
        public virtual ISelectCommandBuilder Select(params string[] fields)
        {
            _fields.Clear();
            if (fields != null && fields.Length > 0)
            {
                foreach (string p in fields)
                {
                    if (string.IsNullOrEmpty(p))
                    {
                        continue;
                    }
                    _fields.Add(p);
                    //if (p.IndexOf(':') > -1) {

                    //}
                }
            }
            return(this);
        }