Skip to content

Instantly share code, notes, and snippets.

@lorddev
Last active March 3, 2018 00:55
Show Gist options
  • Save lorddev/8b11e50968d6be752e0b923b653b89bb to your computer and use it in GitHub Desktop.
Save lorddev/8b11e50968d6be752e0b923b653b89bb to your computer and use it in GitHub Desktop.
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