コード例 #1
0
        /// <summary>
        /// 初始化策略
        /// </summary>
        /// <param name="contentType">输出文档类型</param>
        private void InitStrategy(string contentType)
        {
            //输出Json格式
            if (ContentType.JSON.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseJson.GetInstance();
                return;
            }

            //输出Xml格式
            if (ContentType.XML.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseXml.GetInstance();
                return;
            }

            //表示输出图片或者文件格式的
            if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || contentType.IndexOf("octet-stream", StringComparison.OrdinalIgnoreCase) > 0)
            {
                this._strategy = ResponseFile.GetInstance();
                return;
            }

            //其余 只需直接输出文本均可
            this._strategy = ResponseString.GetInstance();
        }
コード例 #2
0
 /// <summary>
 /// 得到当前的实例
 /// </summary>
 /// <returns></returns>
 public static ResponseDataStrategy GetInstance()
 {
     if (_instance == null)
     {
         _instance = new ResponseJson();
     }
     return(_instance);
 }
コード例 #3
0
 /// <summary>
 /// 得到当前的实例
 /// </summary>
 /// <returns></returns>
 public static ResponseDataStrategy GetInstance()
 {
     if (_instance == null)
     {
         _instance = new ResponseJson();
     }
     return _instance;
 }