-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebClientUtilities.cs
49 lines (29 loc) · 1.28 KB
/
WebClientUtilities.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
using System;
using System.Net;
using System.Reflection;
namespace Gsemac.Net {
public static class WebClientUtilities {
// Public members
public static WebRequest GetWebRequest(WebClient webClient, Uri address) {
MethodInfo getWebRequestMethod = typeof(WebClient)
.GetMethod("GetWebRequest", BindingFlags.NonPublic | BindingFlags.Instance);
return (WebRequest)getWebRequestMethod.Invoke(webClient, new object[] { address });
}
public static WebResponse GetWebResponse(WebClient webClient, WebRequest webRequest) {
MethodInfo getWebRequestMethod = typeof(WebClient)
.GetMethod("GetWebResponse", BindingFlags.NonPublic | BindingFlags.Instance);
return (WebResponse)getWebRequestMethod.Invoke(webClient, new object[] { webRequest });
}
// Internal members
internal static WebClient GetInnermostWebClient(IWebClient webClient) {
switch (webClient) {
case WebClient baseWebClient:
return baseWebClient;
case WebClientAdapter webClientAdapter:
return webClientAdapter.InnerWebClient;
default:
return null;
}
}
}
}