@@ -203,6 +203,7 @@ private IRestRequest AddFile(FileParameter file)
203
203
204
204
/// <summary>
205
205
/// Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
206
+ /// The default format is XML. Change RequestFormat if you wish to use a different serialization format.
206
207
/// </summary>
207
208
/// <param name="obj">The object to serialize</param>
208
209
/// <param name="xmlNamespace">The XML namespace to use when serializing</param>
@@ -239,6 +240,7 @@ public IRestRequest AddBody(object obj, string xmlNamespace)
239
240
240
241
/// <summary>
241
242
/// Serializes obj to data format specified by RequestFormat and adds it to the request body.
243
+ /// The default format is XML. Change RequestFormat if you wish to use a different serialization format.
242
244
/// </summary>
243
245
/// <param name="obj">The object to serialize</param>
244
246
/// <returns>This request</returns>
@@ -247,6 +249,41 @@ public IRestRequest AddBody(object obj)
247
249
return AddBody ( obj , "" ) ;
248
250
}
249
251
252
+ /// <summary>
253
+ /// Serializes obj to JSON format and adds it to the request body.
254
+ /// </summary>
255
+ /// <param name="obj">The object to serialize</param>
256
+ /// <returns>This request</returns>
257
+ public IRestRequest AddJsonBody ( object obj )
258
+ {
259
+ RequestFormat = DataFormat . Json ;
260
+ return AddBody ( obj , "" ) ;
261
+ }
262
+
263
+ /// <summary>
264
+ /// Serializes obj to XML format and adds it to the request body.
265
+ /// </summary>
266
+ /// <param name="obj">The object to serialize</param>
267
+ /// <returns>This request</returns>
268
+ public IRestRequest AddXmlBody ( object obj )
269
+ {
270
+ RequestFormat = DataFormat . Xml ;
271
+ return AddBody ( obj , "" ) ;
272
+ }
273
+
274
+ /// <summary>
275
+ /// Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
276
+ /// Serializes obj to XML format and passes xmlNamespace then adds it to the request body.
277
+ /// </summary>
278
+ /// <param name="obj">The object to serialize</param>
279
+ /// <param name="xmlNamespace">The XML namespace to use when serializing</param>
280
+ /// <returns>This request</returns>
281
+ public IRestRequest AddXmlBody ( object obj , string xmlNamespace )
282
+ {
283
+ RequestFormat = DataFormat . Xml ;
284
+ return AddBody ( obj , xmlNamespace ) ;
285
+ }
286
+
250
287
/// <summary>
251
288
/// Calls AddParameter() for all public, readable properties specified in the includedProperties list
252
289
/// </summary>
@@ -278,18 +315,18 @@ public IRestRequest AddObject(object obj, params string[] includedProperties)
278
315
{
279
316
var elementType = propType . GetElementType ( ) ;
280
317
281
- if ( ( ( Array ) val ) . Length > 0 &&
282
- ( elementType . IsPrimitive || elementType . IsValueType || elementType == typeof ( string ) ) )
318
+ if ( ( ( Array ) val ) . Length > 0 &&
319
+ ( elementType . IsPrimitive || elementType . IsValueType || elementType == typeof ( string ) ) )
283
320
{
284
321
// convert the array to an array of strings
285
322
var values =
286
- ( from object item in ( ( Array ) val ) select item . ToString ( ) ) . ToArray < string > ( ) ;
323
+ ( from object item in ( ( Array ) val ) select item . ToString ( ) ) . ToArray < string > ( ) ;
287
324
val = string . Join ( "," , values ) ;
288
325
}
289
326
else
290
327
{
291
328
// try to cast it
292
- val = string . Join ( "," , ( string [ ] ) val ) ;
329
+ val = string . Join ( "," , ( string [ ] ) val ) ;
293
330
}
294
331
}
295
332
0 commit comments