Exemple #1
0
 protected T GetPathDataValue <T>(string key, T defaultValue = default(T))
 {
     if (PathData.ContainsKey(key))
     {
         Type type  = typeof(T);
         var  value = PathData[key];
         if (RequestBinder.Contains(type))
         {
             return((T)RequestBinder.GetBinder(type).Bind(value, type, defaultValue));
         }
         else if (type.IsEnum)
         {
             return((T)RequestBinder.GetBinder(typeof(Enum)).Bind(value, type, defaultValue));
         }
     }
     return(defaultValue);
 }
Exemple #2
0
        protected T Bind <T>(string parameterName, T defaultValue = default(T))
        {
            Type type       = typeof(T);
            var  nameValues = GetRequestNameValueCollection();

            if (RequestBinder.Contains(type))
            {
                return((T)RequestBinder.GetBinder(type).Bind(nameValues, type, parameterName, defaultValue));
            }
            else if (type.IsEnum)
            {
                return((T)RequestBinder.GetBinder(typeof(Enum)).Bind(nameValues, type, parameterName, defaultValue));
            }
            else
            {
                return(defaultValue);
            }
        }
Exemple #3
0
        protected T Bind <T>() where T : class, new()
        {
            Type type       = typeof(T);
            var  nameValues = GetRequestNameValueCollection();

            if (RequestBinder.Contains(type))
            {
                return((T)RequestBinder.GetBinder(type).Bind(nameValues, type));
            }
            else if (!type.IsValueType)
            {
                return(DtoBinder.CreateInstance <T>(nameValues));
            }
            else
            {
                return(default(T));
            }
        }