Sakura.AspNetCore.Extensions/Sakura.AspNetCore.Mvc.PagedList/Generators/QueryStringLinkGenerator.cs
/// <summary>
///     Change a specified parameter value for an uri.
/// </summary>
/// <param name="baseUri">The uri string which need to be changed.</param>
/// <param name="queryParameterName">The changing query parameter.</param>
/// <param name="queryParameterValue">The new value of the query parameter.</param>
/// <returns>
///     A new uri string which the specified query parameter value is changed; If no matched query parameter is found,
///     append the new value to the end.
/// </returns>
Change a specified parameter value for an uri.
Change a specified parameter value for an uri .
[PublicAPI]
		[Pure]
		protected static Uri ChangeQueryParameterValue(Uri baseUri, string queryParameterName,
			string queryParameterValue)
		{
			var qs = QueryHelpers.ParseQuery(baseUri.Query);
			qs[queryParameterName] = new[] {queryParameterValue};
			var qb = new QueryBuilder();
			foreach (var item in qs)
				qb.Add(item.Key, (IEnumerable<string>) item.Value);
			var builder = new UriBuilder(baseUri)
			{
				Query = qb.ToString().Remove(0, 1) 
			};
			return builder.Uri;
		}
[ PublicAPI ] [ Pure ] protected static Uri ChangeQueryParameterValue ( Uri baseUri , string queryParameterName , string queryParameterValue ) { var qs = QueryHelpers . ParseQuery ( baseUri . Query ) ; qs [ queryParameterName ] = new [ ] { queryParameterValue } ; var qb = new QueryBuilder ( ) ; foreach ( var item in qs ) qb . Add ( item . Key , ( IEnumerable < string > ) item . Value ) ; var builder = new UriBuilder ( baseUri ) { Query = qb . ToString ( ) . Remove ( 0 , 1 ) } ; return builder . Uri ; }
Change a specified parameter value for an uri.
Change a specified parameter value for an uri .
// Extract query string and change parameter // Rebuild uri // Remove leading "?" mark
A new uri string which the specified query parameter value is changed; If no matched query parameter is found,
append the new value to the end.
A new uri string which the specified query parameter value is changed ; If no matched query parameter is found append the new value to the end .
baseUri
Uri
The uri string which need to be changed.
The uri string which need to be changed .
queryParameterName
string
The changing query parameter.
The changing query parameter .
queryParameterValue
string
The new value of the query parameter.
The new value of the query parameter .