public static XPathDocument InputAs <TIn>(TIn input) { if (input == null) { return(null); } if (typeof(TIn).Equals(typeof(string))) { string s = input as string; s = HtmlUtility.ConvertToXml(s); s = LatinGlyphs.Condense(s); return(XmlUtility.GetNavigableDocument(s)); } else if (typeof(TIn).Equals(typeof(XmlDocument))) { return(XmlUtility.GetNavigableDocument(input as XmlDocument)); } else if (typeof(TIn).Equals(typeof(XPathDocument))) { return(input as XPathDocument); } else { return(null); } }
/// <summary> /// Returns strongly typed output, converting the XML fragment. /// </summary> /// <typeparam name="TOut">The <see cref="System.Type"/> of output to return (constrained to <c>class</c>).</typeparam> /// <param name="xmlFragment">An XML fragment or document as a well-formed <see cref="System.String"/>.</param> /// <returns>Returns the specified <see cref="System.Type"/>.</returns> public static TOut OutputAs <TOut>(string xmlFragment) where TOut : class { if (typeof(TOut).Equals(typeof(string))) { return(xmlFragment as TOut); } else { XPathDocument d = XmlUtility.GetNavigableDocument(xmlFragment); return(XmlUtility.OutputAs <TOut>(d)); } }