diff --git a/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs b/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs index 056c2bc..df59a65 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs @@ -342,6 +342,45 @@ public static HttpQueryString ParseQueryString(string str, bool urlencoded) { } + /// + /// Converts the specified string representation of a query string to its + /// equivalent and returns a value that indicates whether the conversion succeeded. + /// + /// A string containing a query string to convert. + /// When this method returns, contains the value equivalent + /// to query string contained in , if the conversion succeeded, or null if the + /// conversion failed. This parameter is passed uninitialized. + /// true if the parameter was converted successfully; otherwise, false. + public bool TryParse(string str, out HttpQueryString result) { + try { + result = ParseQueryString(str); + return true; + } catch { + result = null; + return false; + } + } + + /// + /// Converts the specified string representation of a query string to its + /// equivalent and returns a value that indicates whether the conversion succeeded. + /// + /// A string containing a query string to convert. + /// When this method returns, contains the value equivalent + /// to query string contained in , if the conversion succeeded, or null if the + /// conversion failed. This parameter is passed uninitialized. + /// Whether the query string is URL encoded + /// true if the parameter was converted successfully; otherwise, false. + public bool TryParse(string str, bool urlencoded, out HttpQueryString result) { + try { + result = ParseQueryString(str, urlencoded); + return true; + } catch { + result = null; + return false; + } + } + #endregion #region Operator overloading