百度空间 | 百度首页 
 
查看文章
 
Request扩展的代码(Parameter类)
2008-12-24 11:16

这里是Parameter代码

using System;
using System.Collections.Generic;
using System.Text;

namespace Company.Extend
{
    public class Parameter
    {
        private string _para = "";
        /// <summary>
        /// 参数的原始值
        /// </summary>
        public string ParaVaue
        {
            get
            {
                return _para;
            }
            set
            {
                _para = value;
            }
        }
        public Parameter()
        {
        }
        public Parameter(string para)
        {
            this._para = para;
        }
        /// <summary>
        /// 参数的Int16类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public int? Int16
        {
            get
            {
                //临时值
                int temp = -1;               ;
                if (_para == "")
                {
                    return null;
                }              
                try
                {
                    temp = Convert.ToInt16(_para);
                }
                catch
                {
                    return null;
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的Int32类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public int? Int32
        {
            get
            {
                //临时值
                int temp = -1; ;
                if (_para == "")
                {
                    return null;
                }
                try
                {
                    temp = Convert.ToInt32(_para);
                }
                catch
                {
                    return null;
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的Int64类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public long? Int64
        {
            get
            {
                //临时值
                long temp = -1; ;
                if (_para == "")
                {
                    return null;
                }
                try
                {
                    temp = Convert.ToInt64(_para);
                }
                catch
                {
                    return null;
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的Double类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public double? Double
        {
            get
            {
                //临时值
                double temp = -1; ;
                if (_para == "")
                {
                    return null;
                }
                try
                {
                    temp = Convert.ToDouble(_para);
                }
                catch
                {
                    return null;
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的String类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public string String
        {
            get
            {
                if (_para == "")
                {
                    return null;
                }
                return _para.Trim();
            }
        }
        /// <summary>
        /// 参数的Boolean类型值,如果参数不存在或异常,则返回true;
        /// </summary>
        public bool? Boolean
        {
            get
            {
                //临时值
                bool temp = false;
                if (_para == "")
                {
                    return null;
                }
                try
                {
                    temp = Convert.ToBoolean(_para);
                }
                catch
                {
                    try
                    {
                        temp = Convert.ToBoolean(Convert.ToInt16(_para));
                    }catch
                    {
                        return null;
                    }
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的DateTime类型值,如果参数不存在或异常,则返回null;
        /// </summary>
        public DateTime? DateTime
        {
            get
            {
                //临时值
                DateTime? temp = null;
                if (_para == "")
                {
                    return null;
                }
                try
                {
                    temp = Convert.ToDateTime(_para);
                }
                catch
                {
                   return null;
                  
                }
                return temp;
            }
        }
        /// <summary>
        /// 参数的MD5加密值(小写),如果参数不存在或异常,则返回null;
        /// </summary>
        public string MD5
        {
            get
            {
                if (_para == "")
                {
                    return null;
                }
                //MD5加密
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(_para, "MD5").ToLower();
            }
        }
        /// <summary>
        /// 参数的字符串进行 URL 解码并返回已解码的字符串。如果参数不存在或异常,则返回null;
        /// </summary>
        public string UrlDecode
        {
            get
            {
                if (_para == "")
                {
                    return null;
                }
                System.Web.HttpContext _context = System.Web.HttpContext.Current;
                return _context.Server.UrlDecode(_para.Trim());              
            }
        }
        /// <summary>
        /// 对经过HTML 编码的参数进行解码,并返回已解码的字符串。如果参数不存在或异常,则返回null;
        /// </summary>
        public string HtmlDecode
        {
            get
            {
                if (_para == "")
                {
                    return null;
                }
                System.Web.HttpContext _context = System.Web.HttpContext.Current;
                return _context.Server.HtmlDecode(_para.Trim());
            }
        }
    }
}


类别:Dotnet | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu