-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathRequestStringBuilder.cs
executable file
·57 lines (48 loc) · 1.94 KB
/
RequestStringBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Reflection;
using Newtonsoft.Json;
namespace Stripe.Infrastructure.Middleware
{
public static class RequestStringBuilder
{
private static IEnumerable<IParserPlugin> ParserPlugins { get; }
static RequestStringBuilder()
{
if (ParserPlugins != null) return;
// use reflection so this works on the bin directory?
ParserPlugins = new List<IParserPlugin>
{
new AdditionalOwnerPlugin(),
new ArrayPlugin(),
new DateFilterPlugin(),
new DictionaryPlugin(),
new EnumPlugin(),
new IncludePlugin(),
new OrderItemsPlugin(),
new SubscriptionItemPlugin(),
new SubscriptionItemUpdatedPlugin(),
new InvoiceSubscriptionItemPlugin()
};
}
internal static void ProcessPlugins(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
{
var parsedParameter = false;
foreach (var plugin in ParserPlugins)
{
if(!parsedParameter)
parsedParameter = plugin.Parse(ref requestString, attribute, property, propertyValue, propertyParent);
}
if (!parsedParameter)
ApplyParameterToRequestString(ref requestString, attribute.PropertyName, string.Format(CultureInfo.InvariantCulture, "{0}", propertyValue));
}
public static void ApplyParameterToRequestString(ref string requestString, string argument, string value)
{
var token = "&";
if (!requestString.Contains("?"))
token = "?";
requestString = $"{requestString}{token}{argument}={WebUtility.UrlEncode(value)}";
}
}
}