Created
January 26, 2019 13:09
-
-
Save co89757/c6d134e78edf333df3d2657db2304fad to your computer and use it in GitHub Desktop.
generate url link from route template and routedictionaryvalues in .net core
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
using Microsoft.AspNetCore.Routing.Template; | |
using Microsoft.AspNetCore.Routing; | |
using System.Text.Encodings.Web; | |
using Microsoft.Extensions.ObjectPool; | |
using Microsoft.AspNetCore.Routing.Internal; | |
namespace chat | |
{ | |
public class UrlBuilder | |
{ | |
public static string BuildUri(string routeTemplate, RouteValueDictionary values ){ | |
var template = TemplateParser.Parse(routeTemplate); | |
var urlencoder = UrlEncoder.Create(new TextEncoderSettings{}); | |
var poolpolicy = new UriBuilderContextPooledObjectPolicy(); | |
var pool = new DefaultObjectPool<UriBuildingContext>(poolpolicy); | |
var binder = new TemplateBinder(urlEncoder: urlencoder, pool: pool, template: template, defaults: null); | |
var x = binder.BindValues(values); | |
return x; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment