-
-
Save mostafa-elabady/d8b3954287d97feb9fcf3807f3c83fa3 to your computer and use it in GitHub Desktop.
XML Serialization UWP
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 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