Tool.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using DataObject.Attrib;
using DataObject.Param;
using DataObject.Dele;

namespace DataObject
{
    /// <summary>
    /// 工具类
    /// </summary>
    public sealed class Tool
    {

        /// <summary>
        /// 获取查询字符串
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="sql">实体参数</param>
        /// <returns>查询字符串</returns>
        public static string GetWhere<T>(Sql<T> sql) {
            object obj;
            string s_where = string.Empty, where = string.Empty, pType, value;
            Where<T>[] _wheres = sql.Wheres;
            if (_wheres == null) return GetWhere_Simple(sql);//获取简单查询字符串
            //获取查询字符串
            foreach (Where<T> w in _wheres)
            {
                //设置关联
                where = string.Empty;
                foreach (Filter<T> f in w.Filters){
                    //设置某匹配类型条件(=,>=,>)
                    foreach (PropertyInfo p in f.Value.GetType().GetProperties()){
                        #region 设置筛选值
                        object[] columns = p.GetCustomAttributes(typeof(DBColumn), true);
                        if (columns.Length > 0){
                            obj = p.GetValue(f.Value, null);
                            if (obj == null) continue;
                            //匹配值类型
                            pType = p.PropertyType.ToString();
                            pType = Regex.Match(pType, pType.IndexOf("[") > -1 ? @"(?<=\[\w+\.)[^\]]+" : @"(?<=\.)\w+").Value;
                            switch (pType){
                                case "Boolean": value = (bool)obj ? "1" : "0"; break;
                                case "DateTime":
                                case "String": value = string.Format(f.Mark == "like" ? "{0}" : "'{0}'", obj); break;
                                default: value = obj.ToString(); break;
                            }
                            //设置筛选条件类型 
                            where += string.Format(" and {0} " + (f.Mark == "like" ? "like '%{1}%'" : f.Mark + "{1}"), (columns[0] as DBColumn).Name, value);
                        }
                        #endregion
                    }
                    //多个相同对象串联
                    if (where.Length > 0) {
                        where = Regex.Replace(where, @"(^\sand|(?<=\))\sand)\s", " or (") + ")";
后面还有 58 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。