1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Threading . Tasks ;
3
4
4
5
namespace RestSharp
5
6
{
@@ -106,11 +107,54 @@ public static RestRequestAsyncHandle PatchAsync(this IRestClient client, IRestRe
106
107
return client . ExecuteAsync ( request , callback ) ;
107
108
}
108
109
109
- public static RestRequestAsyncHandle DeleteAsync ( this IRestClient client , IRestRequest request , Action < IRestResponse , RestRequestAsyncHandle > callback )
110
- {
111
- request . Method = Method . DELETE ;
112
- return client . ExecuteAsync ( request , callback ) ;
113
- }
110
+ public static RestRequestAsyncHandle DeleteAsync ( this IRestClient client , IRestRequest request , Action < IRestResponse , RestRequestAsyncHandle > callback )
111
+ {
112
+ request . Method = Method . DELETE ;
113
+ return client . ExecuteAsync ( request , callback ) ;
114
+ }
115
+
116
+ #if NET4
117
+ public static Task < T > GetTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
118
+ {
119
+ return client . ExecuteGetTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
120
+ }
121
+
122
+ public static Task < T > PostTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
123
+ {
124
+ return client . ExecutePostTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
125
+ }
126
+
127
+ public static Task < T > PutTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
128
+ {
129
+ request . Method = Method . PUT ;
130
+ return client . ExecuteTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
131
+ }
132
+
133
+ public static Task < T > HeadTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
134
+ {
135
+ request . Method = Method . HEAD ;
136
+ return client . ExecuteTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
137
+ }
138
+
139
+ public static Task < T > OptionsTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
140
+ {
141
+ request . Method = Method . OPTIONS ;
142
+ return client . ExecuteTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
143
+ }
144
+
145
+ public static Task < T > PatchTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
146
+ {
147
+ request . Method = Method . PATCH ;
148
+ return client . ExecuteTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
149
+ }
150
+
151
+ public static Task < T > DeleteTaskAsync < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
152
+ {
153
+ request . Method = Method . DELETE ;
154
+ return client . ExecuteTaskAsync < T > ( request ) . ContinueWith ( x => x . Result . Data ) ;
155
+ }
156
+ #endif
157
+
114
158
#if FRAMEWORK
115
159
public static IRestResponse < T > Get < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
116
160
{
@@ -148,11 +192,11 @@ public static RestRequestAsyncHandle DeleteAsync(this IRestClient client, IRestR
148
192
return client . Execute < T > ( request ) ;
149
193
}
150
194
151
- public static IRestResponse < T > Delete < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
152
- {
153
- request . Method = Method . DELETE ;
154
- return client . Execute < T > ( request ) ;
155
- }
195
+ public static IRestResponse < T > Delete < T > ( this IRestClient client , IRestRequest request ) where T : new ( )
196
+ {
197
+ request . Method = Method . DELETE ;
198
+ return client . Execute < T > ( request ) ;
199
+ }
156
200
157
201
public static IRestResponse Get ( this IRestClient client , IRestRequest request )
158
202
{
@@ -190,11 +234,11 @@ public static IRestResponse Patch(this IRestClient client, IRestRequest request)
190
234
return client . Execute ( request ) ;
191
235
}
192
236
193
- public static IRestResponse Delete ( this IRestClient client , IRestRequest request )
194
- {
195
- request . Method = Method . DELETE ;
196
- return client . Execute ( request ) ;
197
- }
237
+ public static IRestResponse Delete ( this IRestClient client , IRestRequest request )
238
+ {
239
+ request . Method = Method . DELETE ;
240
+ return client . Execute ( request ) ;
241
+ }
198
242
#endif
199
243
200
244
/// <summary>
@@ -214,20 +258,20 @@ public static void AddDefaultParameter(this IRestClient restClient, Parameter p)
214
258
restClient . DefaultParameters . Add ( p ) ;
215
259
}
216
260
217
- /// <summary>
218
- /// Removes a parameter from the default parameters that are used on every request made with this client instance
219
- /// </summary>
220
- /// <param name="restClient">The IRestClient instance</param>
221
- /// <param name="name">The name of the parameter that needs to be removed</param>
222
- /// <returns></returns>
223
- public static void RemoveDefaultParameter ( this IRestClient restClient , string name )
224
- {
225
- var parameter = restClient . DefaultParameters . SingleOrDefault ( p => p . Name . Equals ( name , StringComparison . OrdinalIgnoreCase ) ) ;
226
- if ( parameter != null )
227
- {
228
- restClient . DefaultParameters . Remove ( parameter ) ;
229
- }
230
- }
261
+ /// <summary>
262
+ /// Removes a parameter from the default parameters that are used on every request made with this client instance
263
+ /// </summary>
264
+ /// <param name="restClient">The IRestClient instance</param>
265
+ /// <param name="name">The name of the parameter that needs to be removed</param>
266
+ /// <returns></returns>
267
+ public static void RemoveDefaultParameter ( this IRestClient restClient , string name )
268
+ {
269
+ var parameter = restClient . DefaultParameters . SingleOrDefault ( p => p . Name . Equals ( name , StringComparison . OrdinalIgnoreCase ) ) ;
270
+ if ( parameter != null )
271
+ {
272
+ restClient . DefaultParameters . Remove ( parameter ) ;
273
+ }
274
+ }
231
275
232
276
/// <summary>
233
277
/// Adds a HTTP parameter (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
0 commit comments