Пример #1
0
        /// <summary>
        /// 根据名称返回参数值。
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="key">参数名称。</param>
        /// <param name="format">用于 DateTime 格式化的字符串。</param>
        /// <returns></returns>
        public static DateTime?GetNullableDateTime(
            this IParamProvider provider, string key, string format)
        {
            var s = provider.GetString(key);

            if (!string.IsNullOrEmpty(s))
            {
                return(DateTime.ParseExact(s, format, null));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// 根据名称返回参数值。
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="key">参数名称。</param>
        /// <param name="default">参数值为 Null 时返回的默认值。</param>
        /// <returns></returns>
        public static int GetInt32(this IParamProvider provider,
                                   string key, int @default = 0)
        {
            var s = provider.GetString(key);
            int ret;

            if (int.TryParse(s, out ret))
            {
                return(ret);
            }
            else
            {
                return(@default);
            }
        }
Пример #3
0
        /// <summary>
        /// 根据名称返回参数值。
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="key">参数名称。</param>
        /// <returns></returns>
        public static double?GetNullableDouble(
            this IParamProvider provider, string key)
        {
            var    s = provider.GetString(key);
            double ret;

            if (double.TryParse(s, out ret))
            {
                return(ret);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// 校验请求。
        /// </summary>
        /// <param name="provider">待校验的请求。</param>
        /// <exception cref="Alipay.Validators.RequiredParameterNotExistException">如果缺少必需参数则抛出异常。</exception>
        public void Validate(IParamProvider provider)
        {
            var requiredAttrs = this.GetRequiredAttributes(provider);

            foreach (RequiredAttribute required in requiredAttrs)
            {
                if (string.IsNullOrEmpty(provider.GetString(required.Key)))
                {
                    throw new RequiredParameterNotExistException
                          {
                              Provider = provider,
                              Key      = required.Key,
                          };
                }
            }
        }