endpoint implementation ...
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System.Text;
|
||||
|
||||
namespace xApi.Extensions
|
||||
{
|
||||
public static class HttpExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Apply Query String to Specified Url ...
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="queries"></param>
|
||||
/// <returns></returns>
|
||||
public static string ApplyQueryString(
|
||||
this string url,
|
||||
IDictionary<string, string>? queries = null
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = url;
|
||||
if (queries is null ||
|
||||
string.IsNullOrWhiteSpace(result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handling ...
|
||||
bool isMarkupAdded = false;
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(result);
|
||||
foreach (var param in queries)
|
||||
{
|
||||
//
|
||||
if (string.IsNullOrWhiteSpace(param.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
sb.Append(isMarkupAdded ? '&' : '?');
|
||||
sb.Append(param.Key);
|
||||
sb.Append('=');
|
||||
sb.Append(param.Value);
|
||||
|
||||
//
|
||||
isMarkupAdded = true;
|
||||
}
|
||||
|
||||
//
|
||||
result = sb.ToString();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user