Skip to content

Instantly share code, notes, and snippets.

@mostafa-elabady
Last active November 24, 2016 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafa-elabady/d8b3954287d97feb9fcf3807f3c83fa3 to your computer and use it in GitHub Desktop.
Save mostafa-elabady/d8b3954287d97feb9fcf3807f3c83fa3 to your computer and use it in GitHub Desktop.
XML Serialization UWP
public abstract class Request<TResponseType> where TResponseType : new()
{
public async Task<ResponseContent> ExecuteAsync<TResponseType>() where TResponseType : new()
{
if (NetworkInformation.IsInternetAvailable())
{
try
{
#region XML Request
if (ResponseFormat == ResponseTypes.XML)
{
//Get the response
try
{
if (ResponseFormat == ResponseTypes.XML)
{
xmlserializer serializer = new xmlserializer(typeof(TResponseType), new xmlrootattribute("response"));
byte[] bytearray = encoding.utf8.getbytes(response.trim());
using (var stream = new memorystream(bytearray))
{
var obj = serializer.deserialize(stream);
content.content = obj;
content.isvalid = true;
}
}
}
catch (Exception ex)
{
}
}
#endregion
else
{
// parse the json response, this works fine.
}
}
catch (Exception ex)
{
//
}
}
else
{
// Handle the no-network case.
}
return content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment