Last active
March 3, 2018 00:55
-
-
Save lorddev/8b11e50968d6be752e0b923b653b89bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class UriExtensions | |
{ | |
public static void AppendPath(this UriBuilder b, string addPath) | |
{ | |
var path = b.Path; | |
if (path.EndsWith("/")) | |
{ | |
path = path.TrimEnd('/'); | |
} | |
if (addPath.StartsWith("/")) | |
{ | |
path += addPath; | |
} | |
else | |
{ | |
path += '/' + addPath; | |
} | |
b.Path = path; | |
} | |
public static void AppendQuery(this UriBuilder b, string name, string value) | |
{ | |
// check for '?...' | |
if (b.Query.Length <= 1) | |
{ | |
b.Query = name + "=" + value; | |
} | |
else | |
{ | |
// b.Query.get always returns '?' | |
// b.Query.set always *adds* '?' so doesn't expect it in value | |
b.Query = b.Query.Substring(1) + '&' + name + '=' + value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment