Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. /// <summary>
  2. /// Returns XML of the Generic Type.
  3. /// </summary>
  4. /// <param name="rssDocument">The RSS document.</param>
  5. /// <typeparam name="T">RssDocumentBase</typeparam>
  6. /// <returns>string</returns>
  7. public static string ToRssXml<T>(T rssDocument) where T : RssDocumentBase
  8. {
  9.     if (rssDocument == null)
  10.     {
  11.         throw new ArgumentNullException("rssDocument");
  12.     }
  13.  
  14.     MemoryStream memoryStream = new MemoryStream();
  15.     String XmlizedString = null;
  16.     using (XmlTextWriter output = new XmlTextWriter(memoryStream, Encoding.UTF8))
  17.     {
  18.  
  19.         XmlSerializer serializer = new XmlSerializer(typeof(T));
  20.         serializer.Serialize(output, rssDocument);
  21.         memoryStream = (MemoryStream)output.BaseStream;
  22.         XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
  23.         return XmlizedString;
  24.     }
  25. }
  26.  
  27. /// <summary>
  28. /// To convert a Byte Array of Unicode values (UTF-8 encoded) to a complete String.
  29. /// </summary>
  30. /// <param name="characters">Unicode Byte Array to be converted to String</param>
  31. /// <returns>String converted from Unicode Byte Array</returns>
  32. private static String UTF8ByteArrayToString(Byte[] characters)
  33. {
  34.     UTF8Encoding encoding = new UTF8Encoding();
  35.     String constructedString = encoding.GetString(characters);
  36.     return (constructedString);
  37. }




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2018