Beispiel #1
0
        /// <summary>
        ///     从当前Http请求中,获取表单中获取值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        public static T GetValue <T>(string key)
        {
            var value = HttpContext.Request.Form[key];

            if (value.IsNullOrEmpty())
            {
                return(Convert.To <T>(null));
            }

            var result = Convert.To <T>(value);

            return(result);
        }
Beispiel #2
0
 /// <summary>
 ///     动态创建实例
 /// </summary>
 /// <typeparam name="T">目标类型</typeparam>
 /// <param name="type">类型</param>
 /// <param name="parameters">传递给构造函数的参数</param>
 public static T CreateInstance <T>(Type type, params object[] parameters)
 {
     return(Convert.To <T>(Activator.CreateInstance(type, parameters)));
 }
Beispiel #3
0
        /// <summary>
        ///     将Id转换成主键类型字段
        /// </summary>
        /// <param name="id">主键ID</param>
        protected TKey ToKey(object id)
        {
            var key = Convert.To <TKey>(id);

            return(key);
        }
 /// <summary>
 ///     获取当前应用程序标识
 /// </summary>
 /// <param name="session">用户会话</param>
 public static T GetApplicationId <T>(this ISession session)
 {
     return(Convert.To <T>(HttpWeb.Identity.GetValue(IdentityClaimTypes.ApplicationId)));
 }
 /// <summary>
 ///     获取当前操作人标识
 /// </summary>
 /// <param name="session">用户会话</param>
 public static T GetUserId <T>(this ISession session)
 {
     return(Convert.To <T>(session.UserId));
 }
Beispiel #6
0
 /// <summary>
 ///     获取枚举值
 /// </summary>
 /// <typeparam name="TResult">返回值类型</typeparam>
 /// <param name="instance">枚举实例</param>
 public static TResult Value <TResult>(this Enum instance)
 {
     return(Convert.To <TResult>(Value(instance)));
 }