• C# 自己用到的几个参数转换方法


     /// <summary>
        /// Method:CommandHelper
        /// Author:Liuyangyi
        /// Data:2016-05-10
        /// </summary>
        public class Command
        {
    
            /// 提供标准 MD5 加密的方法
            /// </summary>
            /// <param name="cort"></param>
            /// <returns></returns>
            /// <summary>
            /// 标准的md5密码加密算法
            /// </summary>
            /// <param name="toCryString"></param>
            /// <returns></returns>
            public static string Ext_GetStandMD5(string toCryString)
            {
                MD5CryptoServiceProvider hashmd5;
                hashmd5 = new MD5CryptoServiceProvider();
                return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(toCryString.Trim()))).Replace("-", "").ToUpper();
            }
            /// <summary>
            /// Unix时间戳
            /// </summary>
            /// <param name="dateTime"></param>
            /// <returns></returns>
            public static string DateTimeToUnixTimestamp()
            {
                DateTime dateTime = DateTime.Now;
                var start = new DateTime(1970, 1, 1, 0, 0, 0, dateTime.Kind);
                return Convert.ToInt64((dateTime - start).TotalSeconds).ToString();
            }
    
            /// <summary>
            /// 时间格式
            /// </summary>
            /// <returns></returns>
            public static string DateTimestamp()
            {
                DateTime dateTime = DateTime.Now;
                return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
            }
            /// <summary>
            /// 除去数组中的空值和签名参数并以字母a到z的顺序排序
            /// </summary>
            /// <param name="dicArrayPre">过滤前的参数组</param>
            /// <returns>过滤后的参数组</returns>
            public static Dictionary<string, object> FilterPara(SortedDictionary<string, object> dicArrayPre)
            {
                Dictionary<string, object> dicArray = new Dictionary<string, object>();
                foreach (KeyValuePair<string, object> temp in dicArrayPre)
                {
                    if (temp.Key.ToLower() != "sign" && temp.Value != null && temp.Value != "")
                    {
                        dicArray.Add(temp.Key, temp.Value);
                    }
                }
    
                return dicArray;
            }
    
            /// <summary>
            /// 
            /// 排序加清除为空的参数
            /// </summary>
            /// <param name="o"></param>
            /// <returns></returns>
            public static Dictionary<String, Object> ToMap(Object o)
            {
                SortedDictionary<String, Object> map = new SortedDictionary<string, object>();
    
                Type t = o.GetType();
    
                PropertyInfo[] pi = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
    
                foreach (PropertyInfo p in pi)
                {
                    MethodInfo mi = p.GetGetMethod();
    
                    if (mi != null && mi.IsPublic)
                    {
                        map.Add(p.Name, mi.Invoke(o, new Object[] { }));
                    }
                }
    
                return FilterPara(map);
    
            }
    
    
    
            /// <summary>
            /// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
            /// </summary>
            /// <param name="dicArray"></param>
            /// <returns></returns>
            public static string CreateLinkString(Dictionary<string, object> dicArray)
            {
                StringBuilder prestr = new StringBuilder();
                foreach (KeyValuePair<string, object> temp in dicArray)
                {
                    if (temp.Key.ToLower() != "sign" && temp.Key.ToLower() != "pid" && temp.Value != null && temp.Value != "")
                    {
                        prestr.Append(temp.Key + "=" + temp.Value.ToString().Replace(" ", "") + "&");
                    }
                }
                //去掉最後一個&字符
                int nLen = prestr.Length;
                prestr.Remove(nLen - 1, 1);
    
                return prestr.ToString();
            }
    
    
    
        }
  • 相关阅读:
    串口数据字节位的理解
    【转】arm-none-linux-gnueabi-gcc下载
    【转】网络排错全面详解
    【转】VMware虚拟机三种网络模式详解
    【转】vi编辑只读文档无法保存的解决办法
    【转】关于在linux下清屏的几种技巧
    【转】64位Ubuntu 16.04搭建嵌入式交叉编译环境arm-linux-gcc过程图解
    ELF文件
    UCOSII内核代码分析
    vmware安装win7提示No CD-ROM drive to use:GCDROM not loaded
  • 原文地址:https://www.cnblogs.com/yiliuyang/p/5511705.html
Copyright © 2020-2023  润新知