Exemplo n.º 1
0
 /// <summary>
 /// Create a document from a text reader.
 /// </summary>
 /// <param name="reader">Document text reader.</param>
 /// <param name="mime">Document mime-type.</param>
 /// <returns>New document instance.</returns>
 public static XDoc From(TextReader reader, MimeType mime)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (mime == null)
     {
         throw new ArgumentNullException("mime");
     }
     if (mime.Match(MimeType.VCAL))
     {
         return(VersitUtil.FromVersit(reader, "vcal"));
     }
     if (mime.Match(MimeType.VERSIT))
     {
         return(VersitUtil.FromVersit(reader, "vcard"));
     }
     if (mime.Match(MimeType.HTML))
     {
         return(FromHtml(reader));
     }
     if (mime.IsXml)
     {
         return(FromXml(reader));
     }
     if (mime.Match(MimeType.FORM_URLENCODED))
     {
         return(XPostUtil.FromXPathValuePairs(XUri.ParseParamsAsPairs(reader.ReadToEnd()), "form"));
     }
     throw new ArgumentException("unsupported mime-type: " + mime.FullType, "mime");
 }