Skip to content

Commit 5afeaa3

Browse files
author
Michael Hallett
committed
Merge branch 'master' of https://github.com/restsharp/RestSharp
Conflicts: RestSharp/IRestRequest.cs RestSharp/RestRequest.cs
2 parents 62774f2 + 35e4013 commit 5afeaa3

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ Download/
3939
restsharp-computed.nuspec
4040
Backup/
4141
*.htm
42+
*.orig

RestSharp.Tests/NamespacedXmlTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Licensed
1+
#region Licensed
22
// Copyright 2010 John Sheehan
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");

RestSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
44
VisualStudioVersion = 12.0.30723.0

RestSharp/IRestRequest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public interface IRestRequest
161161

162162
/// <summary>
163163
/// Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
164+
/// The default format is XML. Change RequestFormat if you wish to use a different serialization format.
164165
/// </summary>
165166
/// <param name="obj">The object to serialize</param>
166167
/// <param name="xmlNamespace">The XML namespace to use when serializing</param>
@@ -169,11 +170,35 @@ public interface IRestRequest
169170

170171
/// <summary>
171172
/// Serializes obj to data format specified by RequestFormat and adds it to the request body.
173+
/// The default format is XML. Change RequestFormat if you wish to use a different serialization format.
172174
/// </summary>
173175
/// <param name="obj">The object to serialize</param>
174176
/// <returns>This request</returns>
175177
IRestRequest AddBody(object obj);
176178

179+
/// <summary>
180+
/// Serializes obj to JSON format and adds it to the request body.
181+
/// </summary>
182+
/// <param name="obj">The object to serialize</param>
183+
/// <returns>This request</returns>
184+
IRestRequest AddJsonBody(object obj);
185+
186+
/// <summary>
187+
/// Serializes obj to XML format and adds it to the request body.
188+
/// </summary>
189+
/// <param name="obj">The object to serialize</param>
190+
/// <returns>This request</returns>
191+
IRestRequest AddXmlBody(object obj);
192+
193+
/// <summary>
194+
/// Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
195+
/// Serializes obj to XML format and passes xmlNamespace then adds it to the request body.
196+
/// </summary>
197+
/// <param name="obj">The object to serialize</param>
198+
/// <param name="xmlNamespace">The XML namespace to use when serializing</param>
199+
/// <returns>This request</returns>
200+
IRestRequest AddXmlBody(object obj, string xmlNamespace);
201+
177202
/// <summary>
178203
/// Calls AddParameter() for all public, readable properties specified in the includedProperties list
179204
/// </summary>

RestSharp/RestRequest.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private IRestRequest AddFile(FileParameter file)
203203

204204
/// <summary>
205205
/// 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.
206207
/// </summary>
207208
/// <param name="obj">The object to serialize</param>
208209
/// <param name="xmlNamespace">The XML namespace to use when serializing</param>
@@ -239,6 +240,7 @@ public IRestRequest AddBody(object obj, string xmlNamespace)
239240

240241
/// <summary>
241242
/// 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.
242244
/// </summary>
243245
/// <param name="obj">The object to serialize</param>
244246
/// <returns>This request</returns>
@@ -247,6 +249,41 @@ public IRestRequest AddBody(object obj)
247249
return AddBody(obj, "");
248250
}
249251

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+
250287
/// <summary>
251288
/// Calls AddParameter() for all public, readable properties specified in the includedProperties list
252289
/// </summary>
@@ -278,18 +315,18 @@ public IRestRequest AddObject(object obj, params string[] includedProperties)
278315
{
279316
var elementType = propType.GetElementType();
280317

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)))
283320
{
284321
// convert the array to an array of strings
285322
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>();
287324
val = string.Join(",", values);
288325
}
289326
else
290327
{
291328
// try to cast it
292-
val = string.Join(",", (string[]) val);
329+
val = string.Join(",", (string[])val);
293330
}
294331
}
295332

0 commit comments

Comments
 (0)