Spotify.NET/SpotifyAPI.Web/Util/URIParameterFormatProvider.cs

28 lines
666 B
C#
Raw Normal View History

2020-05-01 19:05:28 +01:00
using System;
2022-11-27 12:29:35 +00:00
using System.Web;
2020-05-01 19:05:28 +01:00
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
{
return formatType == typeof(ICustomFormatter) ? _formatter : null;
2020-05-01 19:05:28 +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
}
}
}
}