Exemplo n.º 1
0
        /// <summary>
        /// Sets the parameter value escaped by the specified method.
        /// </summary>
        private void SetParam(string name, string value, EscapingMethod escapingMethod)
        {
            if (Params.TryGetValue(name, out Param param))
            {
                if (escapingMethod == EscapingMethod.EncodeUrl)
                {
                    value = HttpUtility.UrlEncode(value); // or WebUtility.UrlEncode or Uri.EscapeDataString
                }
                else if (escapingMethod == EscapingMethod.EncodeJson)
                {
                    value = HttpUtility.JavaScriptStringEncode(value, false);
                }

                foreach (int index in param.PartIndices)
                {
                    StringParts[index] = value;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resets the parameter values.
        /// </summary>
        public void ResetParams(IDictionary <string, string> args, EscapingMethod escapingMethod)
        {
            // clear all parts
            foreach (Param param in Params.Values)
            {
                foreach (int index in param.PartIndices)
                {
                    StringParts[index] = "";
                }
            }

            // set new values
            if (args != null)
            {
                foreach (var arg in args)
                {
                    SetParam(arg.Key, arg.Value, escapingMethod);
                }
            }
        }