Sdl.Web.Mvc/Controllers/BaseController.cs
/// <summary>
/// Tries to get the typed value of a request parameter (from the URL query string) with a given name.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The typed value of the parameter (output).</param>
/// <returns><c>true</c> if the parameter is specified and its value can be converted to the given type; <c>false</c> otherwise.</returns>
Tries to get the typed value of a request parameter (from the URL query string) with a given name.
Tries to get the typed value of a request parameter ( from the URL query string ) with a given name .
protected bool TryGetRequestParameter<T>(string name, out T value)
        {
            string paramValue = Request.Params[name];
            if (string.IsNullOrEmpty(paramValue))
            {
                Log.Debug("Request parameter '{0}' is not specified.", name);
                value = default(T);
                return false;
            }
            try
            {
                value = (T) Convert.ChangeType(paramValue, typeof(T));
                return true;
            }
            catch (Exception)
            {
                Log.Warn("Could not convert value for request parameter '{0}' into type {1}. Value: '{2}'.", name, typeof(T).Name, paramValue);
                value = default(T);
                return false;
            }
        }
protected bool TryGetRequestParameter < T > ( string name , out T value ) { string paramValue = Request . Params [ name ] ; if ( string . IsNullOrEmpty ( paramValue ) ) { Log . Debug ( " " , name ) ; value = default ( T ) ; return false ; } try { value = ( T ) Convert . ChangeType ( paramValue , typeof ( T ) ) ; return true ; } catch ( Exception ) { Log . Warn ( " " , name , typeof ( T ) . Name , paramValue ) ; value = default ( T ) ; return false ; } }
Tries to get the typed value of a request parameter (from the URL query string) with a given name.
Tries to get the typed value of a request parameter ( from the URL query string ) with a given name .
None
name
string
The name of the parameter.
The name of the parameter .
T
out
value
The typed value of the parameter (output).
The typed value of the parameter ( output ) .
typeparam
The type of the value.
The type of the value .