Created
July 5, 2012 09:03
-
-
Save PaulCampbell/3052473 to your computer and use it in GitHub Desktop.
Overriding the rest# serialiser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RestSharpXmlSerializer : RestSharp.Serializers.ISerializer | |
{ | |
public string Serialize(object obj) | |
{ | |
string retval = null; | |
if (obj != null) | |
{ | |
var sb = new StringBuilder(); | |
using (var writer = XmlWriter.Create(sb, new XmlWriterSettings() { OmitXmlDeclaration = true })) | |
{ | |
new System.Xml.Serialization.XmlSerializer(obj.GetType()).Serialize(writer, obj); | |
} | |
retval = sb.ToString(); | |
} | |
return retval; | |
} | |
public string ContentType { get; set; } | |
public string DateFormat { get; set; } | |
public string Namespace { get; set; } | |
public string RootElement { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static RestRequest CreateRequest(string resource) | |
{ | |
var request = new RestRequest | |
{ | |
Resource = resource, | |
XmlSerializer = | |
new RestSharpXmlSerializer | |
{ContentType = "application/xml", DateFormat = DateFormat.RoundTrip} | |
}; | |
return request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment