Exemple #1
0
        /// <summary>
        /// 创建远程代理对象
        /// </summary>
        /// <typeparam name="T">远程对象类</typeparam>
        /// <param name="url">远程对象的URL地址</param>
        public static T CreateProxy <T>(string url)
        {
            //获取远程对象的类型
            Type type = typeof(T);

            return(CommonTranslationHelper.ConvertTo <T>(CreateProxy(type, url)));
        }
Exemple #2
0
        /// <summary>
        /// 获取一个文件的长度,单位为MB
        /// </summary>
        /// <param name="filePath">文件的路径</param>
        public static double GetFileSizeByMB(string filePath)
        {
            //创建一个文件对象
            FileInfo fi = new FileInfo(filePath);

            //获取文件的大小
            return(CommonTranslationHelper.ToDouble(CommonTranslationHelper.ToDouble(fi.Length) / 1024 / 1024));
        }
Exemple #3
0
        /// <summary>
        /// 比较
        /// </summary>
        /// <param name="level">标准</param>
        /// <param name="number"></param>
        /// <returns>0 等于 -1小于 1大于</returns>
        public static int CompareNUM(decimal level, decimal number, string id = "")
        {
            string levelstr = level.ToString();
            string numstr   = "";
            int    p        = -1;

            if (id == "1344")
            {
                numstr = number.ToString("F2");
            }
            else if (id == "1347")
            {
                numstr = CommonTranslationHelper.ParsebyBT8170(number, 1).ToString();
            }
            else
            {
                if ((p = levelstr.LastIndexOf(".")) == -1)
                {
                    numstr = number.ToString("F0");
                }
                else
                {
                    numstr = number.ToString("F" + levelstr.Substring(levelstr.LastIndexOf(".") + 1).Length);
                }
            }
            decimal newnum = decimal.Parse(numstr);

            int result = 0;

            if (newnum > level)
            {
                result = 1;
            }
            else if (newnum < level)
            {
                result = -1;
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 将流读取到缓冲区中
        /// </summary>
        /// <param name="stream">原始流</param>
        public static byte[] StreamToBytes(Stream stream)
        {
            try
            {
                //创建缓冲区
                byte[] buffer = new byte[stream.Length];

                //读取流
                stream.Read(buffer, 0, CommonTranslationHelper.ToInt(stream.Length));

                //返回流
                return(buffer);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //关闭流
                stream.Close();
            }
        }
Exemple #5
0
 /// <summary>
 /// 创建类的实例
 /// </summary>
 /// <typeparam name="T">要转换的类名</typeparam>
 /// <param name="className">类名,格式:"命名空间.类名"</param>
 /// <param name="parameters">传递给构造函数的参数</param>
 public static T CreateInstance <T>(string className, params object[] parameters)
 {
     return(CommonTranslationHelper.ConvertTo <T>(CreateInstance(className, parameters)));
 }