/// <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; } } }
/// <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); } } }