Exemple #1
0
        /// <summary>
        /// 获取map(测试可用)
        /// </summary>
        public static void MapEntity <T>(ref T entity, object model, string[] notmap = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException("对象为空");
            }

            //读取
            var modelproperties = model.GetType().GetProperties().Where(x => x.CanRead).ToList();

            //写入
            var entityproperties = entity.GetType().GetProperties().Where(x => x.CanWrite).ToList();

            if (ValidateHelper.IsNotEmpty(notmap))
            {
                entityproperties = entityproperties.Where(x => !notmap.Contains(x.Name)).ToList();
            }

            foreach (var pi in entityproperties)
            {
                //属性名和属性类型一样
                var modelpi = modelproperties
                              .Where(x => x.Name == pi.Name)
                              .Where(x => x.GetType() == pi.GetType())
                              .FirstOrDefault();

                if (modelpi == null)
                {
                    continue;
                }

                pi.SetValue(entity, modelpi.GetValue(model), null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 通过给定参数生成分页html
        /// </summary>
        /// <param name="url"></param>
        /// <param name="pageKey"></param>
        /// <param name="urlParams"></param>
        /// <param name="itemCount"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static string GetPagerHtmlByData(
            string url, string pageKey,
            Dictionary <string, string> urlParams,
            int itemCount, int page, int pageSize)
        {
            url = ConvertHelper.GetString(url).Trim();
            if (!url.EndsWith("?"))
            {
                url += "?";
            }

            if (ValidateHelper.IsEmpty(pageKey))
            {
                pageKey = "page";
            }

            if (ValidateHelper.IsNotEmpty(urlParams))
            {
                url += urlParams.ToUrlParam();
                url += "&";
            }

            url += pageKey + "={0}";

            int pageCount = GetPageCount(itemCount, pageSize);

            return(GetPagerHtml(page, pageCount, url));
        }
Exemple #3
0
        /// <summary>
        /// 计算签名
        /// </summary>
        /// <param name="dict"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public static (string sign, string sign_data) CreateSign(SortedDictionary <string, string> dict, string salt)
        {
            var strdata = dict.ToUrlParam();

            if (ValidateHelper.IsNotEmpty(salt))
            {
                strdata += salt;
            }
            strdata = strdata.ToLower();

            var md5 = strdata.ToMD5().ToUpper();

            return(md5, strdata);
        }
Exemple #4
0
        public static XmlDocument GetXmlDom(string xmlFilePath, string xmlString)
        {
            var dom = new XmlDocument();

            if (xmlFilePath != null && File.Exists(xmlFilePath))
            {
                dom.Load(xmlFilePath);
                return(dom);
            }
            if (ValidateHelper.IsNotEmpty(xmlString))
            {
                dom.LoadXml(xmlString);
                return(dom);
            }
            throw new Exception("未能提供有效数据");
        }
Exemple #5
0
        /// <summary>
        /// 格式化数字格式
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string FormatNumber(string num)
        {
            var sp = ConvertHelper.GetString(num).Split('.');

            if (sp.Length != 2)
            {
                return(num);
            }
            var right = ConvertHelper.GetString(sp[1]);

            right = right.TrimEnd('0');
            var left = sp[0];

            if (ValidateHelper.IsNotEmpty(right))
            {
                left += "." + right;
            }
            return(left);
        }
Exemple #6
0
        /// <summary>
        /// 使用递归找文件目录
        /// </summary>
        public static void FindFilesBad(DirectoryInfo dir, VoidFunc <FileInfo> func)
        {
            if (dir == null || !dir.Exists)
            {
                return;
            }
            var files = dir.GetFiles();

            if (ValidateHelper.IsNotEmpty(files))
            {
                files.ToList().ForEach(x => { func.Invoke(x); });
            }

            var dirs = dir.GetDirectories();

            if (ValidateHelper.IsNotEmpty(dirs))
            {
                dirs.ToList().ForEach(x => { FindFilesBad(x, func); });
            }
        }
Exemple #7
0
        /// <summary>
        /// 使用栈找文件
        /// </summary>
        public static void FindFiles(string path, VoidFunc <FileInfo> func, VoidFunc <int> stack_count_func = null)
        {
            var root = new DirectoryInfo(path);

            if (!root.Exists)
            {
                throw new NotExistException("目录不存在");
            }

            var stack = new Stack <DirectoryInfo>();

            stack.Push(root);
            DirectoryInfo cur_node = null;

            while (stack.Count > 0)
            {
                stack_count_func?.Invoke(stack.Count);

                cur_node = stack.Pop();
                if (cur_node == null || !cur_node.Exists)
                {
                    break;
                }

                var files = cur_node.GetFiles();
                if (ValidateHelper.IsNotEmpty(files))
                {
                    files.ToList().ForEach(x => { func.Invoke(x); });
                }

                var dirs = cur_node.GetDirectories();
                if (ValidateHelper.IsNotEmpty(dirs))
                {
                    dirs.ToList().ForEach(x => { stack.Push(x); });
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// 判断是否是非空字符串
 /// </summary>
 public static bool IsPlumpString(string str) => ValidateHelper.IsNotEmpty(str);
Exemple #9
0
 /// <summary>
 /// 判断是否是有值的字典
 /// </summary>
 public static bool IsPlumpDict <K, V>(IDictionary <K, V> dict) => ValidateHelper.IsNotEmpty(dict);
Exemple #10
0
 /// <summary>
 /// 判断是否是有值的list
 /// </summary>
 public static bool IsPlumpList <T>(IEnumerable <T> list) => ValidateHelper.IsNotEmpty(list);