2020-05-01 19:05:28 +01:00
|
|
|
using System.Web;
|
|
|
|
using System;
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
public class URIParameterFormatProvider : IFormatProvider
|
|
|
|
{
|
|
|
|
private readonly URIParameterFormatter _formatter;
|
|
|
|
|
|
|
|
public URIParameterFormatProvider()
|
|
|
|
{
|
|
|
|
_formatter = new URIParameterFormatter();
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:43:00 +00:00
|
|
|
public object? GetFormat(Type? formatType)
|
2020-05-01 19:05:28 +01:00
|
|
|
{
|
2020-05-02 12:04:26 +01:00
|
|
|
return formatType == typeof(ICustomFormatter) ? _formatter : null;
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 14:30:00 +01:00
|
|
|
private class URIParameterFormatter : ICustomFormatter
|
2020-05-01 19:05:28 +01:00
|
|
|
{
|
2020-11-13 13:43:00 +00:00
|
|
|
public string Format(string? format, object? arg, IFormatProvider? formatProvider)
|
2020-05-01 19:05:28 +01:00
|
|
|
{
|
2020-11-13 13:43:00 +00:00
|
|
|
return HttpUtility.UrlEncode(arg?.ToString()) ?? string.Empty;
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|