/// <summary>
        ///   Returns a string in the format of a standard querystring, containing the name/value pairs of all properties.
        /// Allows caller to override one param name & its value.  Reconstructs the RequestQueryString using any overrides in the StickyParameter class provided and the new name value pair provided.
        /// </summary>
        /// <param name="overrideParamName">Caller can override one param name.  Use String.Empty to ignore.</param>
        /// <param name="overrideParamVal">Caller can override one param's value.  Use String.Empty to ignore.</param>
        /// <returns></returns>
        protected static string GetQueryString(StickyParameter stickyParameter, string overrideParamName, string overrideParamVal)
        {
            //The heart of QueryString generation in conjunction with ReplaceQueryString.

            StringBuilder qstring  = new StringBuilder("?");
            String        val      = null;
            Object        paramval = null;
            PropertyInfo  prop;

            foreach (String key in stickyParameter.inQS)
            {
                if (key == null)
                {
                    continue;
                }

                prop     = typeof(StickyParameter).GetProperty(key);
                paramval = null;
                val      = null;

                if (prop != null)
                {
                    paramval = prop.GetValue(stickyParameter, null);
                }
                if (paramval != null)
                {
                    if (paramval is ParameterValues)
                    {
                        val = ((ParameterValues)paramval).Value;
                    }
                    else if (prop.PropertyType == typeof(int))
                    {
                        val = ((int)paramval).ToString();
                    }
                    else if (prop.PropertyType == typeof(string))
                    {
                        val = paramval.ToString();
                    }
                    else
                    {
                        try //if not a supported type, then get value from Current Request QueryString
                        {
                            val = (String)stickyParameter.GetParamFromUser(prop.Name);
                        }
                        catch
                        {
                            val = null;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(val))
                {
                    AddToQstring(qstring, key, HttpUtility.UrlEncode(val));
                }
            }

            return(ReplaceQueryString(qstring.ToString(), overrideParamName, overrideParamVal));
        }
Exemplo n.º 2
0
        public static String InitializeProperty(String name, HttpContext context)
        {
            object obj = GetParamFromUser(name, context);

            if (obj == null)
            {
                obj = StickyParameter.GetParamDefault(name);
            }
            if (obj.ToString() == String.Empty)
            {
                obj = null;
            }

            return((obj == null) ?
                   null
                : QueryStringUtils.ContentFilterDecode(obj.ToString())
                   );
        }
 public Object GetParamFromUser(String paramName)
 {
     return(StickyParameter.GetParamFromUser(paramName, HttpContext.Current));
 }
 public String InitializeProperty(String name)
 {
     return(StickyParameter.InitializeProperty(name, HttpContext.Current));
 }